David
David

Reputation: 382

Android Java: Scaling down bitmap while keeping quality?

I have a very high quality PNG, I'd like to scale it down without losing quality.

After importing my image to drawable-mdpi, here's what I've done:

titlelogo = BitmapFactory.decodeResource(getResources(), R.drawable.titlelogo);

titlelogoR = Bitmap.createScaledBitmap(titlelogo,(int)width, (int)(titlelogo.getHeight()*(width/titlelogo.getWidth())), true);

canvas.drawBitmap((Bitmap)titlelogoR,0,0,null);

here's my original image: https://i.sstatic.net/MB8eK.png

and here's what it looks like on my device: https://i.sstatic.net/tldMo.png

thanks in advance!

edit: Q:why do I want to scale the image afterwards rather than beforehand? A:So the image can be the same size on all android devices; is there a better way of achieving this?

SOLVED!

I started my project right from the beginning and put my images in xxhdpi folder

Upvotes: 0

Views: 623

Answers (1)

Falmarri
Falmarri

Reputation: 48559

The ideal way is to scale your image beforehand and put it into the mdpi folder. If you REALLY have to scale it in your app, put it in the raw folder.

Upvotes: 1

Related Questions