Reputation: 562
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)
So essentially, is there a way to make the imageview scale the image like this? Nearest Neighbor Resampling
Upvotes: 3
Views: 1287
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
Reputation: 80
Please try with scale type property for image view as FitXY I guess that will fix your issue
Upvotes: -1