简体   繁体   中英

Android - Bitmap quality loss?

I use transparent png image for my app, but when app runs the image loses its quality and it is not exactly same, its kind of distorted also blurred. Is there something that i can do, like bitmap options?

mBitmap = BitmapFactory.decodeResource(res,R.drawable.img1);

I had this problem too. I did solve it using another format than png (in my case jpg was enough). If you still want to use an alpha channel your only remaining choice is gif, even if this wouldn't be the best choice normally.

Could it be the screen pixel density does not match that of your Bitmap? Unless you specify otherwise, your Bitmap is assumed to be at 160dpi, so it will be rescaled as necessary, depending on the device, when you load it.

You can have different versions of your Bitmap, designed for different pixel densities. Just like app icons, these go into the appropriate res/drawable-*dpi/ subdirectories.

I had the same issue when trying to process pictures from android camera. I solved using this code:

Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDensity = 96;

Bitmap originalPicture = BitmapFactory.decodeFile(pictureFile.getPath(), options );

It seems this problem is related to the RGB format of your image and the dither option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM