Setpixel (the SetPixel solution is not supported for images with indexed pixel formats) and setpixel Indexing

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.