如何在加载位图之前调整图像的尺寸

时间:2014-04-23 19:45:06

标签: android android-layout bitmap bitmapfactory

现在加载图像然后调整大小(宽度/高度),我执行以下操作:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filepath, options);
options.inSampleSize = ImageResizer.calculateInSampleSize(options, x, y);
options.inJustDecodeBounds = false;
Bitmap src = BitmapFactory.decodeFile(filepath, options);

Matrix matrix = new Matrix();
matrix.postScale(x, y);
Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix,true);
return bmp;

这种方法的问题是我首先将“坏”位图加载为src,然后将好位图加载为bmp

位图很贵。我宁愿不加载src,而是在第一次加载之前重新调整我的位图,只加载bmp,也许只加options.inJustDecodeBounds = true。无论如何,有谁知道我怎么做得这么好? 如何有效地调整图像尺寸?

0 个答案:

没有答案
相关问题