0

AFAIK, the inSampleSize attribute of BitmapFactory.options will read a sampled image as per the inSampleSize value. Eg: If value is 4, it will effectively read 1/16 pixels and thus memory required to load it will drastically reduce. Here in fact, it is maintaining the aspect ratio in the sense that it has skipped 1/4th pixels along height and 1/4th pixels along the width. When I load this bitmap in a smaller ImageView, aspect ratio is maintained and it looks good. I have used the following formula to derive the inSampleSize = max(Width/reqWidth, height/reqHeight)
size of the imageview = 100dp * 100dp, I have converted 100dp to pixels as per the screen density and used that result as the reqWidth and reqHeight. (Note: All my images are bigger than the reqWidth and reqHeight)

However If I apply another operation Bitmap.createScaledBitmap() on above reduced version of bitmap, the image gets stretched and does not look good in the View.

I am not able to understand what createScaledBitmap() exactly does?

Sumit Trehan
  • 3,985
  • 3
  • 27
  • 42

1 Answers1

0

Given a Bitmap, let's call it bmp1, the create Scaled bitmap method creates a new Bitmap from bmp1 which is upscaled/downscaled to a new size.

However, since you're doing the scaling yourself, perhaps you should simply call createBitmap() instead? That one will respect the new size you tell it to be, and won't scale the original image, which is what you want from what i understood.

Please correct me if I'm wrong, however.

Shark
  • 6,513
  • 3
  • 28
  • 50
  • Yes I have tried to createBitmap() directly. It was working fine. However I want to know, what is the purpose of createScaledBitmap. What operation does it do on an image? – Sumit Trehan Jan 27 '16 at 16:36
  • It scales it without modifying the original bitmap. – Shark Jan 28 '16 at 14:18