2

I never really noticed it before but when I change the image of an imageview using setImageBitmap, using a bitmap which is decoded from resources using BitmapFactory, then the quality of image deteriorates and I don't know why.

I even played around with BitmapFactoryOptions like options.inPreferredConfig, options.inJustDecodeBounds, options.inDither, but the results were pretty much the same; a poor quality image.

On the other if I just use setImageResource, the image doesn't deteriorates and is in best quality possible.

So basically these two codes

  1. Bitmap b=BitmapFactory.decodeResource(getResources(), R.drawable.keypad,options); iv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.keypad))

  2. iv.setImageResource(R.drawable.messages);

results in different image quality.

Can anybody explain why? And how to solve this quality issue using code 1.

Bart
  • 19,692
  • 7
  • 68
  • 77
user632905
  • 990
  • 9
  • 19

1 Answers1

1

If you have blurry images using the BitmapFactory.decodeResource method, you can use this code:

Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap b = BitmapFactory.decodeResource(getResources(), path, options);
iv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.keypad));

Setting the inScaled parameter of BitmapFactory.Options class to false, will prevent blurry images on low screen resolutions since it will prevent scalling as mentioned in the answer of this previous SO question. Maybe you have already tried this but i thought worth mentioning.

Community
  • 1
  • 1
AggelosK
  • 4,313
  • 2
  • 32
  • 37