android: quality of the images resized in runtime

大憨熊 提交于 2019-11-28 06:01:40
Christopher Orr

Please refer to Romain's answer below.

I would like to delete this answer, but I am unable to since it's marked as accepted.


Note that Android [when this answer was originally written, without explicitly requesting 32-bit colour] would only do 16-bit colour, so there may be times when you get unwanted artifacts.

You can also try using the dither options to tell Android to automatically apply dithering which, while not perfect, can help make things look a bit better.

Instead of resizing at drawing time (which is going to be very costly), try to resize in an offscreen bitmap and make sure that Bitmap is 32 bits (ARGB888).

Check out http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html (To be used with unscaledBitmap = BitmapFactory.decodeStream(in);

You can add quality settings to the image. I'm guessing that the quality is being degraded as you are not passing any settings for how the image should be processed.

Ivo

Implementations of the createScaledBitmap(..) method on older platforms (API level < 12) cause problems when you try to scale an ARGB_8888 Bitmap that has no actual alpha value (i.e. each pixel has alpha = 255), because their hasAlpha flag is set to false. In that case the scaled Bitmap is automatically converted to the RGB_565 format.

Therefore since API level 12 there is a method (in class Bitmap)

setHasAlpha(boolean value);

Which helps to prevent a conversion when using createScaledBitmap(..).

There is a way to use the very same method on API level > 3. It has been present for a very long time, just hidden. All necessary steps including the source code are described here:

https://stackoverflow.com/a/12202069/1082933

Hope this helps.

cottonBallPaws

I had a similar problem and here is what I ended up doing: Quality problems when resizing an image at runtime

Also, if your resizing function does not respect the aspect ratio of the image, the quality gets affected. You can find some resizing algorithm on the web, for instance check this out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!