Yartarus
Yartarus

Reputation: 15

Disable bitmap filtering on Android Canvas

I am trying to display simple pixel art on a canvas, but it gets displayed blurry because of anti-aliasing, bilinear filtering, or possibly something similar. For as far as I know I have no way to identify it specifically.

Other people have asked the same question before, but the answers seem to be very outdated.

What I basically have at the moment:

paint = new Paint();
paint.setAntiAlias(false);
paint.setDither(true);
paint.setFilterBitmap(false);
bitmap = BitmapFactory.decodeResource(res, R.drawable.image);
bitmap = Bitmap.createScaledBitmap(bitmap , 320, 320, false);

canvas.drawBitmap(bitmap , 30, 50, paint);

Edit 1

I've come to the conclusion that it is definitely not anti-aliasing since that would actually try to make the borders smooth. Can anyone recognize what is actually happening?

The original image

Screenshot of the original image

The image after getting brutalized by some unidentified filtering

Upvotes: 1

Views: 702

Answers (1)

AmNiss
AmNiss

Reputation: 11

I added the following code in addition to what you did, and it seems to work.

 BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    options.inDensity = options.inTargetDensity ;

    forestBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.forest_bkg, options);

Upvotes: 1

Related Questions