I'm trying to decode a drawable resource into a bitmap like below.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
int destinationDimension = 128;
options.outHeight = destinationDimension;
options.outWidth = destinationDimension;
bmp = BitmapFactory.decodeResource(context.getResources(), defaultImage, options);
Log.d(TAG, "height = " + bmp.getHeight() + " width = " + bmp.getWidth());
But somehow the decoded bitmap is of dimesion 1344x1344.
height = 1344 width = 1344
How can i get bitmap of dimension 128x128.
options.outHeightis used as an output ofBitmapFactory.decodeResource.You can clearly identify them by
options.out<...>. So after we decodeResource the Bitmap, the resulting height and width will be written intooptions.outHeightandoptions.outWidthYes, and No.
We can resize by using
inSampleSize. However, this will scale the bitmap for 2^n. Detail see here for calculation for inSampleSize: https://developer.android.com/topic/performance/graphics/load-bitmapTo scale bitmap to our destination width/height, use
Bitmap.createScaledBitmap. See here: How to resize image (Bitmap) to a given size?.