How does BitmapData solve the problem of binarization of Verification Code images,

Source: Internet
Author: User

How does BitmapData solve the problem of binarization of Verification Code images,

Sorry, this is an article for help. First, it's hard to avoid being clear and zoom in a bit. below is the picture. There is no binarization above. below is the result after binarization, in fact, I don't know what binary is, that is, a certain range turns black and white.

Problem:

Why are there a lot of colored dots on my results? None of them ......

Who can help me see how to change the code! Thank you !!

Bitmap bit1 = new Bitmap (bit); Rectangle rect1 = new Rectangle (0, 0, bit1.Width, bit1.Height); BitmapData bitd = bit1.LockBits (rect1, ImageLockMode. readWrite, PixelFormat. format24bppRgb); IntPtr srcPtr = bitd. scan0; int scanWidth = bitd. width * 3; int src_bytes = scanWidth * bitd. height; byte [] srcRGBValues = new byte [src_bytes]; Marshal. copy (srcPtr, srcRGBValues, 0, src_bytes); // grayscale processing int m = 0, I = 0, j = 0; // m indicates the row, j indicates that the column int k = 0; for (I = 0; I <bit. height; I ++) // only obtain the rows row pixel value of the image {for (j = 0; j <bit. width; j ++) {// only process the pixel data of each row of the image and Discard unused space. // note that in the bitmap structure, RGB is stored in BGR order. k = 3 * j; var grays = Convert. toInt16 (srcRGBValues [I * scanWidth + k + 2]) + Convert. toInt16 (srcRGBValues [I * scanWidth + k + 1]) + Convert. toInt16 (srcRGBValues [I * scanWidth + k + 0]); if (grays >=382) {srcRGBValues [I * scanWidth + k + 2] = Convert. toByte (255); srcRGBValues [I * scanWidth + k + 1] = Convert. toByte (255); srcRGBValues [I * scanWidth + k + 0] = Convert. toByte (255);} else {srcRGBValues [I * scanWidth + k + 2] = Convert. toByte (0); srcRGBValues [I * scanWidth + k + 1] = Convert. toByte (0); srcRGBValues [I * scanWidth + k + 0] = Convert. toByte (0) ;}} m ++;} Marshal. copy (srcRGBValues, 0, srcPtr, src_bytes); bit1.UnlockBits (bitd); Image image1 = bit1;

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.