I want to load a ImageView with a png file with low resolution. I want to display the pixels but the ImageView is displaying it blurry with interpolation. How can this be avoided? I want to display all the pixels.
This is the way I'm displaying the ImageView:
Drawable dr = getResources().getDrawable(R.drawable.cloud);
Bitmap cloud1Bitmap = ((BitmapDrawable) dr).getBitmap();
float cloud1Ratio = (float)cloud1Bitmap.getHeight()/cloud1Bitmap.getWidth();
cloud1ImageView = new ImageView(this);
cloud1ImageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
cloud1ImageView.setImageBitmap(Bitmap.createScaledBitmap(cloud1Bitmap, cloud1Width, (int) (cloud1Width*cloud1Ratio), true));
main.addView(cloud1ImageView);
EDIT:
Tryed with that function and didn't work. Maybe it's because I'm scaling the image?
view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
width = (int) (sw/3);
Drawable dr = context.getResources().getDrawable(R.drawable.ufo);
BitmapDrawable bd = ((BitmapDrawable) dr);
Bitmap bitmap = bd.getBitmap();
float ratio = (float)bitmap.getHeight()/bitmap.getWidth();
height = (int)(width*ratio);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, width, height, false));
drawable.setFilterBitmap(false);
view.setImageDrawable(drawable);
In the left you can see how the image appears on the game and in the right how is in the original png: