开发者

Confusing PNG banding solutions

I've run into issues with banding of my PNG files. Digging into the problem has yielded two solutions. Both make sense individually, but together they don't. The solutions I've discovered:

1) Move the PNG file into the "raw" folder. This prevents AAPT from "optimizing" the image which results in banding.

2) Change the pixel format of your Activity's window to RGBA_8888 (i.e. in onCreate add this line "getWindow().setFormat(PixelFormat.RGBA_8888)"). On Android 2.2 and lower the default pixel format is 16-bit (565).

I have tried both of these and they correct the banding effect in my images, however now I am even more confused as to what Android is doing.

On the one hand, if I leave my 开发者_如何学PythonPNG in the drawable folder it is "optimized" which results in a banding effect in the image. It magically goes away when I change the pixel format to 32-bit. If the image was "optimized" though, I would have expected the banding to remain.

On the other hand, if I move the PNG to the raw folder it will retain the nice gradient and display nicely even though the pixelFormat is supposedly 16-bit.

If anyone has any insight into what is going on I would appreciate it.

Thanks,

-Dan


I believe its quite simple :

You have to think of the pixel format of your Activity(RGBA_8888) as a DEFAULT optimization for your bitmaps.

If it is not set, then prior to 2.2, by default it will compress your bitmap to RGB_565.

But if you were to create programmatically a bitmap and set it to RGBA_8888, then it would be used as such by the app.

Same applies when you put your bitmap in the raw folder : Even though the default PixelFormat is set to RGB_565, the activity will use it as it is without "optimizing" it.

When you put your bitmap in the raw folder it will not be compressed at all and used as is even though the default PixelFormat is still RGB_565.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜