//------------------------основные функции------------------------ //----------------------------------------------------------------- //сбор данных void save_all_images() { //HtmlElementCollection collect= webBrowser.Document.Images; //System.Net.WebClient web_client = new System.Net.WebClient(); //web_client.DownloadFile(collect[0].GetAttribute("src"), @"C:\Users\asus\Desktop\Diplom\image"); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser.Document.DomDocument; mshtml.IHTMLControlRange imgRange = (mshtml.IHTMLControlRange)((mshtml.HTMLBody)doc.body).createControlRange(); int cnt = 0; string str; foreach (mshtml.IHTMLImgElement img in doc.images) { imgRange.add((mshtml.IHTMLControlElement)img); imgRange.execCommand("Copy", false, null); using (System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap)) { if (bmp != null) { str = img.nameProp; bmp.Save(cnt.ToString()); cnt++; } } } }
public void save_images(HtmlElement elem, string addr_dir = "") { mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser.Document.DomDocument; mshtml.IHTMLControlRange imgRange = (mshtml.IHTMLControlRange)((mshtml.HTMLBody)doc.body).createControlRange(); mshtml.IHTMLImgElement img = (mshtml.IHTMLImgElement)elem.DomElement; imgRange.add((mshtml.IHTMLControlElement)img); imgRange.execCommand("Copy", false, null); using (System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap)) { if (bmp != null) { if (addr_dir == "") { bmp.Save(@"C:\" + "aaaa"); } else { bmp.Save(addr_dir + img.nameProp); } } } }