How to set color to certain pixels of an image
<p>I have an image in an ImageView. I would like to set certain pixels to red. I have made some progress, but the created image has lost its colour. </p>

<pre><code> iv.setImageBitmap(processingBitmap(bitmap));

  private Bitmap processingBitmap(Bitmap src){

        Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());

        for(int x = 0; x &lt; src.getWidth(); x++){
         for(int y = 0; y &lt; src.getHeight(); y++){
          int pixelColor = src.getPixel(x, y);
          int newPixel= Color.rgb(pixelColor, pixelColor, pixelColor);
          dest.setPixel(x, y, newPixel);
         }
        }

        for (int i=5; i&lt;50; i++)
        {
        dest.setPixel(i, i, Color.rgb(255, 0, 0));
        }

        return dest;
       }
</code></pre>

<p><img src="http://i.stack.imgur.com/r0QAr.png" alt="enter image description here"></p>

<p>If I use  <code>Bitmap dest = src.copy(src.getConfig(), src.isMutable());</code> instead of  <code>Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());</code> I get an error to the  <code>iv.setImageBitmap(processingBitmap(bitmap));</code> line:</p>

<blockquote>
  <p>09-06 18:03:37.226: E/AndroidRuntime(811): Caused by:
  java.lang.IllegalStateException 09-06 18:03:37.226:
  E/AndroidRuntime(811):    at
  android.graphics.Bitmap.setPixel(Bitmap.java:847)</p>
</blockquote>

<p>I also don't know why do I have to copy-paste all the pixels and after then set those pixels to red I want. If I use only </p>

<pre><code> for (int i=5; i&lt;50; i++)
        {
        dest.setPixel(i, i, Color.rgb(255, 0, 0));
        }
</code></pre>

<p>I get a black image with the red line.</p>

<p>Any help is appreciated!</p>
