示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ///
            /// 获取webbrowser里的图片
            ///
            HTMLDocument html = (HTMLDocument)webBrowser1.Document.DomDocument;//注意是HTMLDocument而不是HtmlDocument
            //寻找验证码图片,因为没有ID所以得自己定位
            HtmlElement         elem  = webBrowser1.Document.GetElementById("icode");
            IHTMLControlElement img   = (IHTMLControlElement)elem.DomElement;
            IHTMLControlRange   range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();

            range.add(img);
            range.execCommand("Copy", false, null);

            if (Clipboard.ContainsImage())
            {
                Image pic = Clipboard.GetImage();
                this.pictureBox1.Image = pic;

                Bitmap bitmap = (Bitmap)pic.Clone();

                bitmap.Save(Application.StartupPath + "\\numbers\\" + DateTime.Now.Ticks.ToString() + ".bmp");

                JWDecode decode = new JWDecode();
                string   result = decode.Decode(bitmap, Application.StartupPath + "\\numbers2\\");
                label1.Text = result;
            }
        }