Replace black color in bitmap with red

Get all the pixels in the bitmap using this:

int [] allpixels = new int [myBitmap.getHeight() * myBitmap.getWidth()];

myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

for(int i = 0; i < allpixels.length; i++)
{
    if(allpixels[i] == Color.BLACK)
    {
        allpixels[i] = Color.RED;
    }
}

myBitmap.setPixels(allpixels,0,myBitmap.getWidth(),0, 0, myBitmap.getWidth(),myBitmap.getHeight());

Leave a Comment