Setpixel (the SetPixel solution is not supported for images with indexed pixel formats) and setpixel Indexing
A verification code recognition software has been developed recently. The following error occurs when binarization png and jpg images: The SetPixel solution is not supported for images with indexed pixel formats. Literally, this indicates that I have directly set the RGB color of an indexed image, and the color of the indexed image comes from the color palette. Therefore, this operation is invalid. The solution on the internet is unreliable. Close up this article to help new users.
In C ++, I will analyze the color palette offset and convert the color array. However, in the powerful. Net, it is clear that this is not required: the Bitmap object comes with the Clone () function. I only need to Clone a Bitmap object and set PixelFormat to the non-index format. For my software, I use the Format24bppRgb format (the specified format is 24 bits per pixel; the red, green, and blue components each use 8 bits ).
Bitmap img1 = new Bitmap (paths); Bitmap imgtarget = img1.Clone (new Rectangle (0, 0, img1.Width, img1.Height), PixelFormat. Format24bppRgb); // Do something.