Frage

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);
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top