c#取得验证码进行灰度处理(1)

首先在window Form 中添加 PictureBox控件,控件名称为:pictureBox1

 

其次在window form 中添加一个Button,命名为:button2

 

在该按钮的  private void button2_Click(object sender, EventArgs e)事件中添加如下代码

 

 

 HttpWebResponse resp;
            string url = "http://www.my400800.cn/1.jpeg";//换成你自己的验证码生成地址
            WebClient wc = new WebClient();
            HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create((url));
            hwr.Method = "GET";
           
            resp = (HttpWebResponse)hwr.GetResponse();
            Stream resStream = resp.GetResponseStream();
            
            
            Bitmap sourcebm = new Bitmap(resStream);
            pictureBox2.Image = (Bitmap)sourcebm.Clone();
          int iw=  sourcebm.Width;//图片宽度
          int ih = sourcebm.Height;//图片高度
            //图片灰度处理
          for (int i = 0; i < iw; i++) {
              for (int j = 0; j < ih; j++) {


                  Color c = sourcebm.GetPixel(i, j);
                  int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);//转换灰度的算法
                  sourcebm.SetPixel(i, j, Color.FromArgb(luma, luma, luma));
              }
          
          }


            
            pictureBox1.Image = sourcebm;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值