`
ljl_xyf
  • 浏览: 618626 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

    博客分类:
  • c#
阅读更多

首先在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;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics