Mazino
Mazino

Reputation: 562

Android Studio: Imageview background blurs on larger minimum size than image

In Android Studio, I am working with Imageviews and am using relatively small images(10x16px) for larger image views(100s of px).

Like anyone would do, I set my imageview's minimum height/width as needed

Imageview.setMinimumWidth(WIDTH);
Imageview.setMinimumHeight(HEIGHT);

However, when I test my program the initial image scales with lots of blur(image is intended to have a pixel style so the blur is really problematic). The resampling is bilinear I assume.

(gives me this kinda look)

enter image description here

So essentially, is there a way to make the imageview scale the image like this? Nearest Neighbor Resampling

enter image description here

Upvotes: 3

Views: 1287

Answers (2)

Bryan
Bryan

Reputation: 15155

This is occurring because the ImageView has a larger pixel density than the image provided, therefore it has to scale up the image to match the bounds. To avoid this you have two options.

First, you can disable anti-aliasing of the image, which will scale the image without blurring it:

Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.sprite);
BitmapDrawable drawable = new BitmapDrawable(activity.getResources(), bitmap);
drawable.setAntiAlias(false);
imageView.setImageDrawable(drawable);

Or you can provide an image large enough so that it will only ever be scaled down, not up.

Upvotes: 5

Vijayaramanan
Vijayaramanan

Reputation: 80

Please try with scale type property for image view as FitXY I guess that will fix your issue

Upvotes: -1

Related Questions