title: Android: How to use RGB_565 colors in View.onDraw() to match bitmap colors
body: <p>In my application I have a custom view that renders some bitmaps and draws them to the view's canvas using <code>onDraw()</code>. The canvas is filled with a color at first. Essentially I have the following code:</p>
  
  <pre><code>public static int COLOR = Color.rgb(200, 50, 50);
  
  @Override
  public void onDraw(Canvas canvas) {
      canvas.drawColor(COLOR);
  
      Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
      Canvas c = new Canvas(bitmap);
      c.drawColor(COLOR);
  
      canvas.drawBitmap(bitmap, 0, 0, null);
  }
  </code></pre>
  
  <p>I'm expecting the code to create a continuously red screen; the bitmap is rendered in a different shade of red though, so its position is visible. To analyze the colors I made a screenshot of it - the bitmap is drawn with <code>(206,48,49)</code> instead of <code>(200,50,50)</code>.</p>
  
  <p>Obviously this must have to do with the bitmap using RGB_565 instead of ARGB_8888 (which I don't want to use though). So my question is, how can I fill the view's canvas with a RGB_565 color in order to work around those color issues?</p>
  
  <p>I tried converting <code>(200,50,50)</code> to RGB_565 by dropping the least significant bits (<code>red &gt;&gt; 3</code>, <code>green &gt;&gt; 2</code>, <code>blue &gt;&gt; 3</code>), but of course that doesn't make a difference here. What does Android do internally to get <code>(206,48,49)</code> from <code>(200,50,50)</code>? Where is my error in reasoning?</p>