0

While developping an Android App, I saw that all my images displayed from the assets are pixelated.

I'm using this 2 lines to display them:

Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setBackground(imageDrawable);

The images have as dimension: 128/128 or 256/256 and are displayed in a square ImageView.

Do anyone have an idea to keep the quality of my images ?

nobody710
  • 125
  • 1
  • 8

2 Answers2

0

Changing the dimensions of your image can and will decrease the quality. There are a couple of things you can do

  1. Use vectors instead. Vectors can be scaled up and down infinitely without loss of quality.
  2. Use an ImageView height and width that is the same size as your image or smaller and maintains the aspect ratio.
Ryan
  • 658
  • 8
  • 22
  • 3)Use multiple versions of the image for different densities, and pick the right one to use at runtime. This is easier if you put them in resources than in assets, as resources will automatically pick the correct density if set up correctly – Gabe Sechan Feb 27 '18 at 15:55
  • Yes thx, I think I have to use images with dimensions as close as possible to my ImageView dimensions or try with vector – nobody710 Mar 01 '18 at 15:23
0

void setImageDrawable (Drawable drawable)
Sets a drawable as the content of ImageView.

To set drawable to ImageView from java, you need to use setImageDrawable (Drawable drawable) method.

You are setting the drawable as imageView's background, your code should be,
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null); imageView.setImageDrawable(imageDrawable);

Vaibhav Surana
  • 342
  • 4
  • 11