To resize a bitmap in android, I am thinking of doing

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

Please, notice which line is commented out. How would my approach differ (compare and contrast) with the more usual

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

How about if I keep all of them? As in

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filepath, options);
options.inSampleSize = ImageResizer.calculateInSampleSize(options, x, y);
options.outWidth = x;
options.outHeight = y;
options.inJustDecodeBounds = false;
Bitmap bmp = BitmapFactory.decodeFile(filepath, options);
有帮助吗?

解决方案

What are the dangers of setting outWidth and outHeight instead of inSampleSize for decoding bitmap

outWidth and outHeight are output values. They are not input values. Setting them yourself will do nothing useful.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top