13

On emulators running Android 4.0 or 4.0.3, I am seeing horrible colour banding which I can't seem to get rid of. On every other Android version I have tested, gradients look smooth.

I have a SurfaceView which is configured as RGBX_8888, and the banding is not present in the rendered canvas. If I manually dither the image by overlaying a noise pattern at the end of rendering I can make the gradients smooth again, though obviously at a cost to performance which I'd rather avoid.

So the banding is being introduced later. I can only assume that, on 4.0+, my SurfaceView is being quantized to a lower bit-depth at some point between it being drawn and being displayed, and I can see from a screen capture that gradients are stepping 8 values at a time in each channel, suggesting a quantization to 555 (not 565).

I added the following to my Activity onCreate function, but it made no difference.

getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

I also tried putting the above in onAttachedToWindow() instead, but there was still no change.

(I believe that RGBA_8888 is the default window format anyway for 2.2 and above, so it's little surprise that explicitly setting that format has no effect on 4.0+.)

Which leaves the question, if the source is 8888 and the destination is 8888, what is introducing the quantization/banding and why does it only appear on 4.0+?

Very puzzling. I wonder if anyone can shed some light?

  • 1
    possible duplicate of [Bitmaps on ICS are loaded with wrong pixel format](http://stackoverflow.com/questions/9097887/bitmaps-on-ics-are-loaded-with-wrong-pixel-format) – Sergey Glotov Mar 21 '12 at 20:08
  • Thanks for that link... does indeed look like the same problem. Some answers suggest that it may simply be an emulator problem and, although there's no definitive answer, I'm going to go with that for now. – threeshinyapples Mar 23 '12 at 13:47
  • I'm having the exact same problem. I was able to remove the issue on v2.2+ and v2.3+, but not v4.0+ I'd love to know if someone knows a solution to this? – Sent1nel Jul 08 '12 at 20:53
  • 1
    I am having this problem too which messed up my captured screenshots. I am seeing this even on the built-in wallpapers so part of the problem is definitely due to artifacts of OpenGL ES emulation (according to error messages, i can only run software renderer. maybe hardware renderer will alleviate this problem?): I am seeing no such horror on a real Galaxy Nexus. – Falcon Jul 18 '12 at 05:23
  • I'm having the same problem in the emulator. Neither `getBackground().setDither(true)` nor `getWindow().setFormat(PixelFormat.RGBA_8888)` worked. I also found a hardware property in the AVD - `LCD Color Depth` which defaults to 16 and set it to 32. No difference. – Code Poet Jul 20 '12 at 17:09
  • 1
    PS: For me, the layout with the gradient background looks fine in the `Graphical Layout View`. – Code Poet Jul 20 '12 at 17:12
  • Can/have you tested on an actual device to see if its not just an emulator issue? – Shaun Jan 20 '13 at 16:47

2 Answers2

2

Try dis..

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options);

findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));
Tej
  • 399
  • 1
  • 5
  • 21
0

Turning on the emulator "Use Host GPU" option fixed the color problems for me, credit goes to this answer https://stackoverflow.com/a/17166234/1287459

In my case I was using Android 4.2.2.

Community
  • 1
  • 1
Georgie
  • 2,448
  • 2
  • 17
  • 13