title: Bitmaps on ICS are loaded with wrong pixel format
body: <p>I encountered the following problem. When any bitmap is loaded from resources by an application running on Ice Cream Sandwich, it will likely be rendered incorrectly as if it has been decoded to the format, which differs from the current window format, with no dither applied. However, both, the decoding format and window format have been explicitly set:</p>
  
  <pre><code>BitmapFactory.Options opts = new BitmapFactory.Options();
  opts.inPreferredConfig = Bitmap.Config.RGBA_8888;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>getWindow().setFormat(PixelFormat.RGBA_8888);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
  </code></pre>
  
  <p>Here are screenshots of the <a href="http://www.curious-creature.org/data/BitmapConfig.zip" rel="nofollow noreferrer">test app</a> taken from <a href="http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/" rel="nofollow noreferrer">this article</a> running on Emulator with ICS 4.0.3 (it gives the same results on HTC HD2):</p>
  
  <p><code>RGBA_8888</code> (32-bits) <strong>window format</strong>, various bitmap decoding formats:
  <img src="https://i.stack.imgur.com/S9EAi.png" alt="32-bit window format"></p>
  
  <p><code>RGB_565</code> (16-bits) <strong>window format</strong>, various bitmap decoding formats:
  <img src="https://i.stack.imgur.com/rtgIe.png" alt="16-bit window format"></p>
  
  <p>Several things could be noticed:</p>
  
  <ul>
  <li>Dithering flag is not taken into account from time to time;</li>
  <li>The default window format for ICS seems to be <code>RGB_565</code>;</li>
  <li>The only good looking gradient appears with <code>RGB_565</code> <strong>window format</strong> and <code>RGBA_8888</code> <strong>bitmap decoding format</strong>.</li>
  </ul>
  
  <p>This problem has also been reported in these questions, but still no solution can be found there:</p>
  
  <p><a href="https://stackoverflow.com/questions/8636388/gradient-compatibility-issue-ics-defaults-to-fewer-colors-than-all-the-previou">Gradient compatibility issue - ICS defaults to fewer colors than all the previous versions of Android</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8417608/awful-background-image-quality-in-android">Awful background image quality in Android</a></p>
  
  <p>The quistion is, how to deal with all these formats on ICS, to be more precise, how to make ICS load bitmaps with <code>RGBA_8888</code> format and how to set the window format to <code>RGBA_8888</code> so these bitmaps are displayed correctly?</p>