예제 #1
0
        private Image GetWebImage(HTMLDocument doc, IHTMLControlElement ImgeTag)
        {
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = ImgeTag; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            try
            {
                if (oldImage != null)
                {
                    Clipboard.SetImage(oldImage);
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show("GetWebImage:" + ex.Message);
            }

            return(numImage);
        }
예제 #2
0
        /// <summary>
        /// 需配合被辨識的網頁做調整
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var forms = webBrowser1.Document.GetElementsByTagName("form");
            // 取得整個網頁的DOM
            var doc  = webBrowser1.Document.DomDocument as HTMLDocument;
            var body = doc.body as HTMLBody;
            IHTMLControlRange range = (IHTMLControlRange)body.createControlRange();

            // 取得驗證碼圖片
            var imgEle = (forms[0].GetElementsByTagName("img"))[1].DomElement as IHTMLControlElement;

            range.add(imgEle);
            range.execCommand("copy", false, Type.Missing);
            Application.DoEvents();

            // 將圖片轉換成.Net物件
            Image img = Clipboard.GetImage();

            Clipboard.Clear();
            pictureBox1.Image = img;
            Application.DoEvents();

            // 將驗證碼圖片灰階化以提高辨識的準確性
            pictureBox2.Image = convert2GrayScale(pictureBox1.Image);
            Application.DoEvents();

            // 使用Tessnet Library辨識驗證碼
            textBox2.Text = parseCaptchaStr(pictureBox2.Image);
            Application.DoEvents();
        }
        /*
         *
         *  示例1:
         *  下面是某个站的注册码图片的HTML部分源代码
         *  <IMG height=80 alt="Registration Verification Code" src="......" width=290 border=0>
         *  picturebox1.Image =GetRegCodePic(wbMail, "", "", "Registration Verification Code")
         *
         *  示例2:
         *  下面是某个站的注册码图片的HTML部分源代码
         *  <IMG id=CAPTCHAImage src="......." name=CAPTCHAImage>
         *  picturebox1.Image =GetRegCodePic(wbMail, "CAPTCHAImage", "", "")  //通过验证码Html元素的名字来
         *
         */
        #endregion

        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <param name="wbMail"></param>
        /// <param name="ImgName"></param>
        /// <param name="Src"></param>
        /// <param name="Alt"></param>
        /// <returns></returns>
        public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
        {
            HTMLDocument        doc  = (HTMLDocument)wbMail.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img;

            if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
            {
                int ImgNum = GetPicIndex(wbMail, Src, Alt);
                if (ImgNum == -1)
                {
                    return(null);
                }
                Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
            }
            else
            {
                Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement;
            }
            rang.add(Img);
            rang.execCommand("Copy", false, null);
            Image RegImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(RegImg);
        }
예제 #4
0
        private Image GetCheckImage(HtmlElement ImageTag)
        {
            HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;

            HTMLBody body = (HTMLBody)doc.body;

            IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();

            IHTMLControlElement Img = (IHTMLControlElement)ImageTag.DomElement; //圖片地址

            bool containImg  = Clipboard.ContainsImage();
            bool containText = Clipboard.ContainsText();

            Image  oldImage = Clipboard.GetImage();
            string oldText  = Clipboard.GetText();

            rang.add(Img);

            rang.execCommand("Copy", false, null); //拷貝到內存

            Image numImage = Clipboard.GetImage(); //從Clipboard中取圖

            if (containImg)
            {
                try { Clipboard.SetImage(oldImage); } //還原
                catch { }
            }
            else if (containText)
            {
                try { Clipboard.SetText(oldText); } //還原
                catch { }
            }

            return(numImage);
        }
예제 #5
0
        //取得驗證碼圖片
        public Image GetRegCodePic(WebBrowser WB, String ImgName, String Src, String Id)
        {
            HTMLDocument        doc  = WB.Document.DomDocument as HTMLDocument;
            HTMLBody            body = doc.body as HTMLBody;
            IHTMLControlRange   rang = body.createControlRange() as IHTMLControlRange;
            IHTMLControlElement Img;

            if (ImgName == "")
            {
                //如果沒有圖片的名字,通過Src或Alt中的關鍵字來取
                Int32 ImgNum = GetPicIndex(WB, Src, Id);
                if (ImgNum == -1)
                {
                    return(null);
                }
                Img = WB.Document.Images[ImgNum].DomElement as IHTMLControlElement;
            }
            else
            {
                Img = WB.Document.All[ImgName].DomElement as IHTMLControlElement;
            }
            rang.add(Img);
            rang.execCommand("copy", false, Type.Missing);
            Image RegImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(RegImg);
        }
예제 #6
0
        public string GetQikanGuid()
        {
            IHTMLDocument2    doc      = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            string html = webBrowser1.DocumentText;

            foreach (IHTMLElement ele in doc.all)
            {
                if (!(ele is IHTMLAnchorElement))
                {
                    continue;
                }
                IHTMLAnchorElement anchor = ele as IHTMLAnchorElement;
                string             href   = anchor.href;
                if (string.IsNullOrEmpty(href) == false && href.IndexOf("magdetails") != -1)
                {
                    string word  = "magdetails/";
                    int    index = href.IndexOf(word);
                    if (index == -1)
                    {
                        return(null);
                    }
                    string result = href.Substring(index + word.Length);
                    index = result.IndexOf("/");
                    if (index == -1)
                    {
                        return(null);
                    }
                    return(result.Substring(0, index));
                }
            }

            return(null);
        }
예제 #7
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        public static Image GetWebImage(Form1 form, WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            Image image = null;

            form.Invoke((EventHandler)(delegate
            {
                // 这里写你的控件代码,比如
                HTMLDocument doc = (HTMLDocument)WebCtl.Document.DomDocument;
                HTMLBody body = (HTMLBody)doc.body;
                IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement Img = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

                Image oldImage = Clipboard.GetImage();
                rang.add(Img);
                rang.execCommand("Copy", false, null);  //拷贝到内存
                image = Clipboard.GetImage();
                try
                {
                    Clipboard.SetImage(oldImage);
                }
                catch
                {
                }
            }
                                       ));

            return(image);
        }
예제 #8
0
        private async Task <ImageSource> GetVerifyCodeInternal()
        {
            //await HookScript(WebBrowser, "/Assets/Json.js");
            //await HookScript(WebBrowser, "/Assets/GetCode.js");
            //var resultData = WebBrowser.Document.InvokeScript("GetCode");

            //var result = JsonConvert.DeserializeObject<ImageSize>(resultData.ToString());

            //if (result.ErrorCode != ErrorCode.Ok)
            //{
            //    throw new Exception($"{result.ErrorCode}");
            //}


            foreach (HtmlElement image in WebBrowser.Document.Images)
            {
                var dom = (IHTMLImgElement)image.DomElement;
                if (dom.src == "http://www.tsdm.net/plugin.php?id=oracle:verify")
                {
                    HTMLBody          body = (HTMLBody)WebBrowser.Document.Body.DomElement;
                    IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                    rang.add((IHTMLControlElement)dom);
                    var result = rang.execCommand("Copy");

                    await Task.Delay(1000);

                    Bitmap bitmap = (Bitmap)System.Windows.Forms.Clipboard.GetImage();
                    var    s      = BitmapToBitmapSource(bitmap);
                    return(s);
                }
            }

            return(null);
        }
예제 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            //to use following DOM classes, u need to add reference to Microsoft.mshtml
            //using mshtml;

            IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;

            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                imgRange.add((IHTMLControlElement)img);

                imgRange.execCommand("Copy", false, null);

                try
                {
                    using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                        bmp.Save(img.nameProp + ".jpg");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #10
0
        private void DownloadCaptcha(WebBrowser w)
        {
            TypeConverter  tc = TypeDescriptor.GetConverter(typeof(Bitmap));
            IHTMLDocument2 doc;

            try
            {
                doc = (IHTMLDocument2)w.Document.Window.Frames[1].Document.DomDocument;
            }
            catch
            {
                doc = (IHTMLDocument2)w.Document.DomDocument;
            }
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                imgRange.add((IHTMLControlElement)img);
                imgRange.execCommand("Copy", false, null);
                using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                {
                    bmp.Save(@"Captcha.png");
                }
            }
        }
예제 #11
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;
            }
        }
예제 #12
0
 private void timer_0_Tick_5(object sender, EventArgs e)
 {
     try
     {
         this.SetVerifyVisible(true);
         this.timer_0.Stop();
         if (!this.bool_0)
         {
             this.method_7();
         }
         this.method_9("正在【打码】!");
         this.ihtmldocument2_0 = (IHTMLDocument2)this.webBrowserLoginAlimama.Document.DomDocument;
         IHTMLControlRange   hTMLControlRange   = (IHTMLControlRange)((HTMLBody)this.ihtmldocument2_0.body).createControlRange();
         IHTMLControlElement hTMLControlElement = (IHTMLControlElement)this.ihtmldocument2_0.all.item("J_StandardCode_m", 0);
         hTMLControlRange.@add(hTMLControlElement);
         hTMLControlRange.execCommand("Copy", false, null);
         Image image = Clipboard.GetImage();
         this.pictureBoxVerify.Image = image;
         this.textBoxVerify.Focus();
         this.image_0 = image;
         (new Thread(new ThreadStart(this.method_8))).Start();
     }
     catch (Exception exception)
     {
         this.method_9(string.Concat("[inputVerifyCode]出错了!", exception.ToString()));
     }
 }
예제 #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            var id = ConfigurationManager.AppSettings["ImgId"];

            var img = webBrowser1.Document.GetElementById(id);

            img.InvokeMember("click");

            HTMLDocument        html  = (HTMLDocument)this.webBrowser1.Document.DomDocument;
            IHTMLControlElement img2  = (IHTMLControlElement)webBrowser1.Document.Images[id].DomElement;
            IHTMLControlRange   range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();

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

            if (Clipboard.ContainsImage())
            {
                pictureBox1.Image = Clipboard.GetImage();
            }
            else
            {
                MessageBox.Show("获取验证码失败");
            }

            Clipboard.Clear();

            pictureBox2.Image = VerificationCode.ProcessBmp(new Bitmap(pictureBox1.Image));
            textBox1.Text     = VerificationCode.Spot(new Bitmap(pictureBox1.Image), 4);
        }
예제 #14
0
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            #region Güvenlik Kodu Resmi Çekme
            IHTMLDocument2    doc    = (IHTMLDocument2)webBrowser1.Document.DomDocument;             // unmanaged document nesnesini alıyoruz
            IHTMLControlRange imgler = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange(); // controlRange ile Html nesne dizisi oluşturuyoruz

            foreach (IHTMLImgElement img in doc.images)                                              // Tüm img elementleri için
            {
                imgler.add((IHTMLControlElement)img);                                                // Koleksiyona elementi ekliyoruz
                imgler.execCommand("copy", false, null);                                             // Koleksiyonu Clipboard a kopyalıyoruz

                using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))   // Clipboard daki resmi bitmap olarak alıyoruz
                {
                    arr.Clear();
                    bmp1 = Image.FromHbitmap(bmp.GetHbitmap());
                    pictureBox1.Image = bmp1;
                    for (int i = 0; i < bmp1.Width; i++)
                    {
                        for (int k = 0; k < bmp1.Height; k++)
                        {
                            arr.Add(bmp1.GetPixel(i, k).Name);
                        }
                    }
                }
            }
            #endregion

            //Veritabanı Güncelleme
            listele();

            timer2.Enabled = true;
        }
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            try
            {
                textBox2.Clear();

                kaynakKod = webBrowser1.Document.Body.InnerHtml.ToString();                              // site kaynak kod

                IHTMLDocument2    doc    = (IHTMLDocument2)webBrowser1.Document.DomDocument;             // unmanaged document nesnesini alıyoruz
                IHTMLControlRange imgler = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange(); // controlRange ile Html nesne dizisi oluşturuyoruz

                foreach (IHTMLImgElement img in doc.images)                                              // Tüm img elementleri için
                {
                    imgler.add((IHTMLControlElement)img);                                                // Koleksiyona elementi ekliyoruz
                    imgler.execCommand("copy", false, null);                                             // Koleksiyonu Clipboard a kopyalıyoruz

                    using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))   // Clipboard daki resmi bitmap olarak alıyoruz
                    {
                        pictureBox1.Image = Image.FromHbitmap(bmp.GetHbitmap());                         // Picturebox ta gösteriyoruz
                    }
                    break;
                }
            }
            catch { }
        }
예제 #16
0
        /// <summary>
        /// 获取WebBrowser指定的图片
        /// </summary>
        /// <param name="webBrowser">需要获取图片的WebBrowser</param>
        /// <param name="imgID">指定的图片的id(优先查找指定id)</param>
        /// <param name="imgSrc">指定的图片的src,支持模糊查询</param>
        /// <param name="imgAlt">指定的图片的src, 支持模糊查询</param>
        /// <returns></returns>
        public static Image GetRegCodePic(ref WebBrowser webBrowser, String imgID, String imgSrc, String imgAlt)
        {
            HTMLDocument        doc  = (HTMLDocument)webBrowser.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img;

            // 如果没有图片的ID,通过Src或Alt中的关键字来取
            if (imgID.Length == 0)
            {
                Int32 ImgNum = GetPicIndex(ref webBrowser, ref imgSrc, ref imgAlt);

                if (ImgNum == -1)
                {
                    return(null);
                }

                img = (IHTMLControlElement)webBrowser.Document.Images[ImgNum].DomElement;
            }
            else
            {
                img = (IHTMLControlElement)webBrowser.Document.All[imgID].DomElement;
            }

            rang.add(img);
            rang.execCommand("Copy", false, null);
            Image regImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(regImg);
        }
예제 #17
0
        /// <summary>
        /// The currently selected text/controls will be replaced by the given HTML code.
        /// If nothing is selected, the HTML code is inserted at the cursor position
        /// </summary>
        /// <param name="s_Html"></param>
        /// <returns></returns>
        public bool PasteIntoSelection(string s_Html)
        {
            if (m_pDoc2 == null)
            {
                return(false);
            }
            IHTMLSelectionObject sel = m_pDoc2.selection as IHTMLSelectionObject;

            if (sel == null)
            {
                return(false);
            }
            IHTMLTxtRange range = sel.createRange() as IHTMLTxtRange;

            if (range == null)
            {
                return(false);
            }
            //none
            //text
            //control
            if ((!String.IsNullOrEmpty(sel.EventType)) &&
                (sel.EventType == "control"))
            {
                IHTMLControlRange ctlrange = range as IHTMLControlRange;
                if (ctlrange != null) //Control(s) selected
                {
                    IHTMLElement elem = null;
                    int          ctls = ctlrange.length;
                    for (int i = 0; i < ctls; i++)
                    {
                        //Remove all selected controls
                        elem = ctlrange.item(i);
                        if (elem != null)
                        {
                            RemoveNode(elem, true);
                        }
                    }
                    // Now get the textrange after deleting all selected controls
                    range = null;
                    range = sel.createRange() as IHTMLTxtRange;
                }
            }

            if (range != null)
            {
                // range will be valid if nothing is selected or if text is selected
                // or if multiple elements are seleted
                range.pasteHTML(s_Html);
                range.collapse(false);
                range.select();
            }
            return(true);
        }
예제 #18
0
        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <param name="imgId"></param>
        /// <returns></returns>
        private Image GetValidateCode(string imgId)
        {
            Image               myImage = new Bitmap(60, 20);
            HtmlDocument        doc     = webBrowser1.Document;
            IHTMLControlElement img     = (IHTMLControlElement)doc.Images[imgId].DomElement;
            IHTMLDocument2      tmpDoc  = webBrowser1.Document.DomDocument as IHTMLDocument2;
            HTMLBody            body    = (HTMLBody)tmpDoc.body;
            IHTMLControlRange   rang    = (IHTMLControlRange)body.createControlRange();

            rang.add(img);
            rang.execCommand("Copy", false, null);
            myImage = Clipboard.GetImage();
            return(myImage);
        }
예제 #19
0
        /// <summary>
        /// 获取图像内容
        /// </summary>
        /// <param name="browser">显示图像的浏览器控件</param>
        /// <param name="imgElement">从浏览器中读取到的img</param>
        private static Image GetImage(WebBrowser browser, HtmlElement imgElement)
        {
            HTMLDocument        doc  = (HTMLDocument)browser.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(imgElement.DomElement);

            rang.add(img);
            rang.execCommand("Copy", false, null);
            Image regImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(regImg);
        }
예제 #20
0
        private void SelectImage()
        {
            // We don't want a selection changed event to fire during the initial insert.
            if (_invocationSource == ImageDecoratorInvocationSource.InitialInsert)
            {
                return;
            }

            IHTMLTextContainer textContainer = ((IHTMLDocument2)_element.document).body as IHTMLTextContainer;
            IHTMLControlRange  controlRange  = textContainer.createControlRange() as IHTMLControlRange;

            controlRange.add(_element as IHTMLControlElement);
            controlRange.select();
        }
예제 #21
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="webCtl">WebBrowser控件</param>
        /// <param name="imgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser webBrowser, string imgeTagId)
        {
            System.Windows.Forms.HtmlDocument winHtmlDoc = webBrowser.Document;
            HTMLDocument        doc    = (HTMLDocument)winHtmlDoc.DomDocument;
            HtmlElement         imgTag = winHtmlDoc.GetElementById(imgeTagId);
            HTMLBody            body   = (HTMLBody)doc.body;
            IHTMLControlRange   rang   = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement imgE   = (IHTMLControlElement)imgTag.DomElement; //图片地址

            rang.add(imgE);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            return(numImage);
        }
예제 #22
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument        doc  = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            Clipboard.SetImage(oldImage);
            return(numImage);
        }
예제 #23
0
    private void ProcessImagesFromDocument()
    {
        IHTMLDocument2    doc      = (IHTMLDocument2)webBrowser1.Document.DomDocument;
        IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

        foreach (IHTMLImgElement img in doc.images)
        {
            imgRange.add((IHTMLControlElement)img);
            imgRange.execCommand("Copy", false, null);

            using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
            {
                bmp.Save(@"C:\" + img.nameProp);
            }
        }
    }
예제 #24
0
        /// <summary>
        /// 得到验证码图片
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="ImgName"></param>
        /// <returns></returns>
        public static Image GetPic(HtmlDocument doc, string ImgName)
        {
            Image        RegImg;
            HTMLDocument domDoc = (HTMLDocument)doc.DomDocument;

            HTMLBody            body = (HTMLBody)domDoc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img;


            Img = (IHTMLControlElement)doc.All[ImgName].DomElement;

            rang.add(Img);
            rang.execCommand("Copy", false, null);
            RegImg = Clipboard.GetImage();
            Clipboard.Clear(); return(RegImg);
        }
예제 #25
0
        public void GetCacheImage(WebBrowser webBrower, string id, MyDelegate myDelegate, Window window)
        {
            HTMLDocument doc  = (HTMLDocument)webBrower.Document;
            HTMLBody     body = (HTMLBody)doc.body;

            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(doc.getElementById(id));

            rang.add(img);
            rang.execCommand("Copy", true, null);
            try
            {
                BitmapSource bitmap = Clipboard.GetImage();
                byte[]       dcimg  = ConvertToBytes(bitmap);//验证码字节码
                Clipboard.Clear();
                string result           = Dc.RecByte_A(dcimg, dcimg.Length, ConfigurationManager.AppSettings["chaorenuser"], ConfigurationManager.AppSettings["chaorenpw"], ConfigurationManager.AppSettings["softid"]);
                string verificationCode = result.Substring(0, result.IndexOf("|!|"));
                myDelegate(verificationCode);
                doc  = null;
                body = null;
                rang = null;
                img  = null;
                GC.Collect();
            }
            catch (Exception e)
            {
                Thread thr = new Thread(() =>
                {
                    string userSaveFiler = Directory.GetCurrentDirectory() + "\\weeorlog.txt";//用户账号保存文件
                    FileStream fs        = new FileStream(userSaveFiler, FileMode.OpenOrCreate);
                    StreamWriter sw      = new StreamWriter(fs);
                    sw.WriteLine(e.ToString());
                    sw.Close();
                    fs.Close();
                    //这里还可以处理些比较耗时的事情。
                    Thread.Sleep(1000);//延时2秒
                    window.Dispatcher.Invoke(new Action(() =>
                    {
                        Clipboard.Clear();
                        GetCacheImage(webBrower, id, myDelegate, window);
                    }));
                });
                thr.Start();
            }
        }
예제 #26
0
 public void CopyClip()
 {
     try
     {
         string            image_name = "temp.bmp";
         IHTMLDocument2    document   = (IHTMLDocument2)webBrowser1.Document.DomDocument;
         IHTMLControlRange imgRange   = (IHTMLControlRange)((HTMLBody)document.body).createControlRange();
         Clipboard.Clear();
         imgRange.add(document.all.item("loginfrm:j_idt11"));
         imgRange.execCommand("Copy");
         using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
         {
             bmp.Save(image_name);
         }
     }
     catch (Exception x) {
     }
 }
예제 #27
0
        //讀入驗證碼
        private Image Getimage()
        {
            HTMLDocument      doc   = webBrowser1.Document.DomDocument as HTMLDocument;
            HTMLBody          body  = doc.body as HTMLBody;
            IHTMLControlRange range = body.createControlRange();
            //取得網頁中第[0]個圖片(因為我要取得的圖片的沒有ID)
            //也可使用GetElementById("ID名稱")取得圖片
            IHTMLControlElement imgElement =
                webBrowser1.Document.GetElementsByTagName("img")[0].DomElement as IHTMLControlElement;

            //複製圖片至剪貼簿
            range.add(imgElement);
            range.execCommand("copy", false, Type.Missing);
            //取得圖片
            img = Clipboard.GetImage();
            Clipboard.Clear();
            return(img);
        }
예제 #28
0
        private Bitmap GetLoginCaptchaImage()
        {
            Bitmap            image     = null;
            IHTMLDocument2    doc       = (IHTMLDocument2)_wbMain.Document.DomDocument;
            HtmlDocument      d         = _wbMain.Document;
            IHTMLControlRange imgRange1 = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                imgRange1.add((IHTMLControlElement)img);
                object a = Clipboard.GetDataObject();

                imgRange1.execCommand("Copy", false, null);
                image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
            }

            return(image);
        }
예제 #29
0
        public bool CopyImageToClipboard()
        {
            IHTMLDocument2    doc      = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                string alt = img.alt;
                if (alt.IndexOf("期") != -1)
                {
                    imgRange.add(img as IHTMLControlElement);

                    imgRange.execCommand("Copy", false, null);
                    return(true);
                }
            }

            return(false);
        }
예제 #30
0
        private void GetImages()
        {
            string dirPath = Utils.Instance.GetAndCreateDirectoryPath();

            path_tbx.Text = "";
            IHTMLDocument2    doc      = (IHTMLDocument2)villa_wbr.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            int k = 0;

            foreach (IHTMLImgElement img in doc.images)
            {
                imgRange.add((IHTMLControlElement)img);

                imgRange.execCommand("Copy", false, null);

                using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                {
                    if ((bmp != null) &&
                        (bmp.Size.Width >= 100) &&
                        (bmp.Size.Height >= 100))
                    {
                        string namePath = k.ToString() + ".jpg";
                        if (img.nameProp.ToLower().Substring(img.nameProp.Length - 5).Contains(".gif"))
                        {
                            namePath = k.ToString() + ".gif";
                        }
                        //string namePath = img.nameProp.ToLower().Replace(".jpg", "") + ".jpg";
                        bmp.Save(Path.Combine(dirPath, namePath));
                        k++;
                    }
                    //return bmp;//bmp.Save(@"C:\" + img.nameProp);
                }
            }
            path_tbx.Text = dirPath;
            path_tbx.SelectAll();

            //WebClient wc = new WebClient();
            //byte[] bytes = wc.DownloadData(url);
            //Bitmap b = new Bitmap(new MemoryStream(bytes));
            //return b;
        }
예제 #31
0
        public void UpdateSelection(IHTMLControlRange selection)
        {
            if (selection != null)
                selection.select();

            //fire the selection changed event since the IHTMLControlRange object doesn't
            (MshtmlEditor.MshtmlControl.DocumentEvents as HTMLDocumentEvents2).onselectionchange(null);
        }