C# 即使webbrowser具有ScrollBarsEnable true,如何将webbrowser控件内的图像保存到硬盘?
这是我现在使用的代码:C# 即使webbrowser具有ScrollBarsEnable true,如何将webbrowser控件内的图像保存到硬盘?,c#,.net,winforms,webbrowser-control,C#,.net,Winforms,Webbrowser Control,这是我现在使用的代码: int imagescount = 0; private void SaveImageFromWebBrowser() { Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height); webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height)); bit
int imagescount = 0;
private void SaveImageFromWebBrowser()
{
Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height));
bitmap.Save(@"e:\webbrowserimages\wbImage" + imagescount.ToString("D6") + ".bmp",
System.Drawing.Imaging.ImageFormat.Bmp);
bitmap.Dispose();
imagescount++;
}
问题是一些图像较大,然后有滚动条,其他图像较小,因此Webbropower不需要滚动条。
但是有滚动条的大图像硬盘上的图像我看到了整个Webbropower控件的滚动条
我想在浏览器控件中获取整个图像。只保存图像,不保存整个控件 首先,您需要向项目添加一个名为:Microsoft.mshtml的引用 然后: 工作得很好
int imagescount = 0;
private void SaveImageFromWebBrowser()
{
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(@"e:\webbrowserimages\Image" + imagescount.ToString("D6") + ".bmp",
System.Drawing.Imaging.ImageFormat.Bmp);
}
imagescount++;
}
}