質問

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