简体   繁体   English

Android-位图质量损失?

[英]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. 我为我的应用程序使用了透明的png图像,但是当应用程序运行时,该图像会失去其质量并且不完全相同,其失真的类型也会模糊。 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). 我确实使用png以外的其他格式解决了它(在我的情况下jpg就足够了)。 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. 如果您仍想使用Alpha通道,则唯一剩下的选择就是gif,即使通常这不是最佳选择。

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. 除非另有说明,否则假定您的位图为160dpi,因此在加载时会根据设备的需要对它进行重新缩放。

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. 就像应用程序图标一样,这些图标进入相应的res / drawable- * dpi /子目录。

I had the same issue when trying to process pictures from android camera. 尝试从android相机处理图片时遇到相同的问题。 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. 似乎此问题与图像的RGB格式和抖动选项有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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