c#实现识别图片上的验证码数字

这篇博客分享了如何使用C#进行验证码数字的识别,提供了两种不同的实现方法,并包含了一个通用类的示例代码,对C#开发者具有参考价值。
摘要由CSDN通过智能技术生成

这篇文章主要介绍了c#实现识别图片上的验证码数字的方法,本文给大家汇总了2种方法,有需要的小伙伴可以参考下。

public void imgdo(Bitmap img)
    {
      //去色
      Bitmap btp = img;
      Color c = new Color();
      int rr, gg, bb;
      for (int i = 0; i < btp.Width; i++)
      {
        for (int j = 0; j < btp.Height; j++)
        {
          //取图片当前的像素点
          c = btp.GetPixel(i, j);
          rr = c.R; gg = c.G; bb = c.B;
          //改变颜色
          if (rr == 102 && gg == 0 && bb == 0)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          }
          if (rr == 153 && gg == 0 && bb == 0)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          } if (rr == 153 && gg == 0 && bb == 51)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          } if (rr == 153 && gg == 43 && bb == 51)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          }
          if (rr == 255 && gg == 255 && bb == 0)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          }
          if (rr == 255 && gg == 255 && bb == 51)
          {
            //重新设置当前的像素点
            btp.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
          }
        }
      }
      btp.Save("d:\\去除相关颜色.png");
 
      pictureBox2.Image = Image.FromFile("d:\\去除相关颜色.png");
 
 
      //灰度
      Bitmap bmphd = btp;
      for (int i = 0; i < bmphd.Width; i++)
      {
        for (int j = 0; j < bmphd.Height; j++)
        {
          //取图片当前的像素点
          var color = bmphd.GetPixel(i, j);
 
          var gray = (int)(color.R * 0.001 + color.G * 0.700 + color.B * 0.250);
 
          //重新设置当前的像素点
          bmphd.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
        }
      }
      bmphd.Save("d:\\灰度.png");
      pictureBox27.Image = Image.FromFile("
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值