title: Get and set bitmap colour table in android
body: <p>I've got a bunch of small two colour png images and I'd like to effectively change one of the two colours to another one. Say <code>RED =&gt; BLUE</code>.</p>
  
  <p>I know I can either loop over each pixel or use <code>Bitmap.setXfermode</code> to do this but it feels like a big waste on such a simple problem. What I want to do is to access the header of the file and change it in the colour table directly. This hints that <code>png:</code>s are indexed <a href="http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap" rel="nofollow">http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap</a> :</p>
  
  <blockquote>
    <p>Note: Bitmap files may be automatically optimized with lossless image compression by the aapt tool. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build. If you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ folder instead, where they will not be optimized.</p>
  </blockquote>
  
  <p>The files I put in the "project" are indexed png images so I know for sure they are in fact indexed and does have a colour table. Will I have to read the files as binary data and manipulate before I make a Bitmap object? I would really prefer if that wasn't the case but there instead is some hidden Bitmap.switchColor (<code>Col1, Col2</code>); which would do just that since I want to be able to switch back or to a third colour.</p>
  
  <p>Please only android related answers and not general ones since I'm only looking for how to do it in android, using android classes.</p>
  
  <p>Thanks in advance</p>