缩放:
public static Bitmap getScaleBitmap(Bitmap bitmap,int newWIDth,int newHeight) { int wIDth = bitmap.getWIDth(); int height = bitmap.getHeight(); float scaleWIDth = ((float) newWIDth) / wIDth; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postscale(scaleWIDth,scaleHeight); return Bitmap.createBitmap(bitmap,wIDth,height,matrix,false);}
抽样:
mImageVIEw.setimageBitmap(decodeSampledBitmapFromresource(getResources(),R.ID.myimage,100,100));public static Bitmap decodeSampledBitmapFromresource(Resources res,int resID,int reqWIDth,int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res,resID,options); options.inSampleSize = calculateInSampleSize(options,reqWIDth,reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res,options);}public static int calculateInSampleSize( BitmapFactory.Options options,int reqHeight) { final int height = options.outHeight; final int wIDth = options.outWIDth; int inSampleSize = 1; if (height > reqHeight || wIDth > reqWIDth) { final int halfheight = height / 2; final int halfWIDth = wIDth / 2; while ((halfheight / inSampleSize) >= reqHeight && (halfWIDth / inSampleSize) >= reqWIDth) { inSampleSize *= 2; } } return inSampleSize;}
这里两个代码执行图像调整大小但不同的方式,所以我如何识别哪一个是好的和简单的.
解决方法 缩放:首先,您在内存中解码整个位图,然后进行缩放.采样:您可以获得所需的缩放位图,而无需在内存中加载整个位图.
总结以上是内存溢出为你收集整理的android – 位图的缩放和采样有什么区别?全部内容,希望文章能够帮你解决android – 位图的缩放和采样有什么区别?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)