Android Bitmap Resize

What is the best way to resize a bitmap?

Using

options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mandy_moore, options); 

or

 Bitmap resizedbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true); 
+6
source share
3 answers

What is the best way to resize a bitmap?

It depends on your flexibility:

options.inSampleSize = N; means that you get an image that is N times smaller than the original. Basically, the decoder will read 1 pixel every N pixel.

Use this option if you do not need a specific size for your bitmap, but you need to reduce it in order to use less memory. This is especially useful for reading large images.

Bitmap.createScaledBitmap , on the other hand, gives you more control: you can specify the exact size of the bitmap, ...

It is best to use a combination of both methods:

  • Define the maximum inSampleSize value that you can use to efficiently decode the original image (so that the decoded image is still larger than the final size).
  • Use Bitmap.createScaledBitmap to precisely control the resulting size
+13
source

Use this to create a sampled image that supports the same aspect ratio as the original image. This is the best way to resize.

 options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mandy_moore, options); Bitmap resizedbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true); 

This will scale the bitmap in condition w and h. This may distort the bitmap.

Use according to your needs.

+13
source

createScaledBitmap method creates low quality images

accept suggestion from this message bitmap quality

-1
source

All Articles