Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing PNG banding solutions

Tags:

android

png

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 PNG 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

like image 856
Dan Avatar asked Feb 07 '11 14:02

Dan


People also ask

How do you fix banding problems?

Avoid banding by making a well-exposed photograph and saving it as an uncompressed RAW file. To fix color banding, make subtle edits and limit how much you compress the photo when exporting as a JPEG. If banding is harsh and distracting, try disguising it by adding a blur and some noise to the area.

How do I get rid of photo banding?

Right-click the bottom layer and choose “Flatten” to merge all the layers together into a single image again. Photoshop will dither the banding automatically and you should see it all smooth out and blend much more realistically.

Can color banding be fixed?

How to fix color banding? This quickest and easiest way to fix color banding is to first see if you have over-processed your image. Check your sliders and pull them back and see if that makes a difference. If you have added a gradient make sure that you haven't added too much saturation or dehaze.

How do you get rid of color banding?

So, if the file you've encountered banding issue with is a 16-bit file, the only way to fix it is to add noise. Here's how do it most effectively: Create a new Overlay layer filled with 50% gray by clicking Control+Shift+N and setting mode to Overlay and checking “Fill with Overlay-neutral color (50% gray).


1 Answers

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.

like image 53
Yahel Avatar answered Sep 22 '22 03:09

Yahel