標籤:style class blog code java http
/// <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(); try { Clipboard.SetImage(oldImage); } catch { } return numImage;}
調用
HtmlElement ImgeTag = webBrowser2.Document.All["id"];//根據驗證碼id擷取元素,根據實際情況更改Image numPic = GetWebImage(webBrowser2, ImgeTag); // 得到驗證碼圖片piccode.Image = numPic;