2

I have been told that calling getWindow().setFormat(PixelFormat.XXXX); should set the pixel format for the window in an activity to XXXX (e.g. RGBA_8888). I have tried calling getWindow().setFormat(PixelFormat.XXXX); in the onCreate method of my activity, but can see no difference in the characteristics of my displayed images regardless of what parameter I use. In particular I am rendering some bitmaps that contain subtle changes of colour that have been showing banding on the android devices. But I can neither make the banding better or worse regardless of what PixelFormat I use (e.g. RGB_332 appears no worse). I strongly suspect that getWindow().setFormat(PixelFormat.XXXX); is not having any effect at all - or that somehow some subsequent code is changing the Format, for example when I create a canvas,? or a view? or on onResume??

I can confirm that there is no banding when I look at the png of the bitmaps on my development PC (32 bit graphics).

EDIT: I just added some test code to draw a set of thin lines across the screen (canvas.drawLine(x,y,x2,y2,paint);) where the paint separately has red green and blue scanning from 0 to 255. The resulting image is here

enter image description here

There appear to be 32 bands of colour for red and blue and 64 for green... implying that the screen format is five bits for each of red and blue and six bits for green - looks like "RGB_565" to me. I then tried getWindow().setFormat(PixelFormat.RGBA8888); early in onCreate and it made no difference - still 32/64 bands.

Mick
  • 8,284
  • 22
  • 81
  • 173
  • There is some editing going on at compile-time. Please put the image into `/res/raw/` and display it from there. Check if this is the culprit. Also, [this](http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/). – tilpner Jan 10 '14 at 19:08
  • I presume you meant bin/res ? ... if so I can confirm that the png in there looks perfectly smooth (no banding) when viewed on my PC. – Mick Jan 10 '14 at 19:11
  • Sort of related: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/ – fadden Jan 11 '14 at 01:12

2 Answers2

2

I had the line

final SurfaceHolder holder = getHolder();

in my code. I then changed this to

final SurfaceHolder holder = getHolder();
holder.setFormat(PixelFormat.RGBA_8888);

and everything worked beautifully (no banding at all) from then on.

Mick
  • 8,284
  • 22
  • 81
  • 173
  • Crazy this is still not the default mode for a surface view when everything is. Thanx for pointing this out!!! – slott May 12 '15 at 09:46
0

Try to add this into your AndroidManifest.xml in order to avoid the default RGB_565:

<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
Vladyslav Savchenko
  • 1,282
  • 13
  • 10