문제

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