I am working with Images in Java, I have designed more over 100+ images(.png) format, They were all Trasparent and Black Color Drawing.
The problem is, Now I have been asked to change the color of the Drawing (Black -to ).
I have searched many code snipped at google,that changes the Bitmap (pixels) of the Image, but i am not guessing what i have to do to match the exact pixel and replace specially when the images if in Transparent mode.
Below is the code in .Net (C#)
Bitmap newBitmap = new Bitmap(scrBitmap.Width, scrBitmap.Height);
for (int i = 0; i < scrBitmap.Width; i++)
{
for (int j = 0; j < scrBitmap.Height; j++)
{
originalColor = scrBitmap.GetPixel(i, j);
if(originalColor = Color.Black)
newBitmap.SetPixel(i, j, Color.Red);
}
}
return newBitmap;
but it was not matching at all, I debugged it, throughout the file, there was no value of Red,Green,Blue parameters of Color (originalColor) variable.
Anybody can help?
Best Answer
Here is the Solution I have done with Pixels.
Attaching the source code so one can try the exact and get the result.
I have sample images of 128x128 (Width x Height).
//Below is the sample image and different results by applying different color![enter image description here](https://i.stack.imgur.com/s3hWj.png)
Code modifications will be highly appreciated.