I am trying to set the color of an image given pixel. Here is the code snippet
bitmap myBitmap = new bitmap (@ "c: \ file.bmp"); (Int Xcount = 0; Xcount & lt; myBitmap.Width; Xcount ++) {For (Int Ycount = 0; Yakt & lt; myBitmap.Height; Ycount ++) {myBitmap.SetPixel (Xcount, Ycount, Color. Black); }}
Every time I get the following exception:
obsolete exception: system. Unknown Operation Exception: Set pixel is not supported for pictures with indexed pixel formats. / P>
Exception is made for two bmp
and jpg
files.
try the following
bitmap myBitmap = new bitmap (@ " C: \ file.bmp "); MessageBox.Show (myBitmap.PixelFormat.ToString ());
If you get "Format 8 BPP Insert", then the color of each pixel of the bitmap is replaced by an index in the table of 256 colors. And for each pixel represented by it is only a byte, you can get an array of colors:
if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed) {color [] colorpal = myBitmap Palette.Entries; }
Comments
Post a Comment