I'm writing a card game and need my cards to be different sizes in different circumstances. I am storing my images as bitmaps so that they can be quickly drawn and redrawn (for animation).
My problem is that no matter how I try and scale my images (whether through a matrix.postScale, a matrix.preScale, or a createScaledBitmap function) they always come out pixelated and blurry. I know that its the scaling thats causing the problem because the images look perfect when drawn without resizing.
I have worked through every solution described in these two threads:
android quality of the images resized in runtime
quality problems when resizing an image at runtime
but still haven't gotten anywhere.
I store my bitmaps (into a hashmap) with this code:
cardImages = new HashMap<Byte, Bitmap>();
cardImages.put(GameUtil.hearts_ace, BitmapFactory.decodeResource(r, R.drawable.hearts_ace));
public void drawCard(Canvas c)
//retrieve the cards image (if it doesn't already have one)
if (image == null)
image = Bitmap.createScaledBitmap(GameUtil.cardImages.get(ID),
(int)(GameUtil.standardCardSize.X*scale), (int)(GameUtil.standardCardSize.Y*scale), false);
//this code (non-scaled) looks perfect
//image = GameUtil.cardImages.get(ID);
//These methods make it look worse
//This code makes absolutely no difference
Paint drawPaint = new Paint();
c.drawBitmap(image, matrix, drawPaint);
I had blury images on low screen resolutions until I disabled scaling on bitmap load from resources:
Options options = new BitmapFactory.Options(); options.inScaled = false; Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);