Setting pixel color of BMP/JPG file in C#.
Posted
by Jamie
on Stack Overflow
See other posts from Stack Overflow
or by Jamie
Published on 2010-05-15T12:45:29Z
Indexed on
2010/05/15
12:54 UTC
Read the original article
Hit count: 306
Hi guys, I'm trying to set a color of given pixel of the image. Here is the code snippet
Bitmap myBitmap = new Bitmap(@"c:\file.bmp");
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
}
Every time I get the following exception:
Unhandled Exception: System.InvalidOperationException: SetPixel is not supported for images with indexed pixel formats.
The exception is thrown both for bmp and jpg files.
I have no idea what is wrong.
Thank you in advance for the reply!
Cheers.
© Stack Overflow or respective owner