0

To avoid out of memory exceptions it is recommended to use sampling. (see Strange out of memory issue while loading an image to a Bitmap object)

But these algorithms do not scale if the new image is less than required image width and height. How to increase the size of the image to fit the layout.

Is it ok to use following code?

   if(inputBitmap.getHeight() < imageheight || inputBitmap.getWidth() < imageWidth) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(inputBitmap,
                            (imageWidth), (imageheight), true);
                    inputBitmap.recycle();
                    inputBitmap = scaledBitmap;
  }
Community
  • 1
  • 1
pats
  • 1,273
  • 2
  • 20
  • 43

1 Answers1

0

Did you try to set the

android:scaleType

attribute to "center" or "centerCrop" in your ImageView XML element?

Ivan V
  • 3,024
  • 4
  • 26
  • 36