I’m trying to scale a tiny image (something like 20×40 pixels) to an arbitrarily large image. I’m doing the scaling by setting the ImageView.scaleType property, but while it does scale the image, it fades from one original pixel color to the next, creating a large blurry version of the image.
Here’s some context for the question. I’m trying to create an old school 16-bit style game for Android. I want to store the sprites/etc as tiny files, and then scale them larger depending on the user’s screen size. That way, I don’t have to create a ton of different images at different sizes for each sprite. Right now I’m just working on a proof of concept, so I’m trying to scale a tiny 20×40 image file to the size of the entire screen.
*edit: I figured out how to use the method Reflog recommended. However, it still does some fading, just far less than the default algorithm.
*edit2: Got it! I had to turn anti-aliasing off
*edit3: This mysteriously stopped working for me, and I found another place where dithering/auto scaling needed to be disabled. Added the options lines.
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setDither(false);
paint.setAntiAlias(false);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tinyimg, options);
canvas.drawBitmap(bitmap, null, new RectF(getLeft(), getTop(), getRight()/2, getBottom()/2), paint);
}
Use:
to use NN scaling, this will reduce blurring, but also will reduce the quality of the scaling.