Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top