Example #1
0
        private static System.Drawing.Bitmap ProcessImage(System.Drawing.Bitmap image)
        {
            System.Drawing.Bitmap bitmap = null;
            try
            {
                bitmap = image.Clone(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), image.PixelFormat);
                CaptchaInfo captchaInfo = new CaptchaInfo();
                bitmap = bitmap.AdjustCurves(127).RemoveNoise(new string[]
                {
                    "ff000000"
                }).GetCaptchaInfo(ref captchaInfo);
                System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#" + captchaInfo.CaptchaColor);
                float num       = c.BrightnessLevel();
                byte  threshold = (byte)(80f * num + 50f);
                if (c.B >= 250 && c.R == 0 && c.G == 0)
                {
                    threshold = 144;
                }
                else if (c.B >= 250 && (c.R == 0 || c.G == 0))
                {
                    threshold = 135;
                }
                else if (c.R == 255 && c.G == 255)
                {
                    threshold = 142;
                }
                bitmap = image.AdjustCurves(threshold)
                         .RemoveNoise(new string[] { "ff000000" })
                         .CleanUnecessaryPixel(captchaInfo).GetLongColoredText();

                //bitmap.Save("Test.jpg");
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            return(bitmap);
        }