[英]Capture WebBrowser Image
使用saveFileDialog保存后,此代碼返回白色圖像
private void salvaUnImmagineToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
SaveAsBitmap(webBrowser1, saveFileDialog1.FileName);
}
}
public void SaveAsBitmap(Control control, string fileName)
{
//getthe instance of the graphics from the control
Graphics g = control.CreateGraphics();
//new bitmap object to save the image
Bitmap bmp = new Bitmap(control.Width, control.Height);
//Drawing control to the bitmap
control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));
bmp.Save(fileName);
bmp.Dispose();
}
我如何捕獲網絡瀏覽器的圖像?
嘗試這個 ...
public partial class Form1 : Form
{
WebBrowser wb = new WebBrowser();
public Form1()
{
InitializeComponent();
wb.Height = 100;
wb.Width = 100;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}
void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Bitmap bmp = new Bitmap(100, 100);
wb.DrawToBitmap(bmp, new Rectangle(wb.Location.X, wb.Location.Y, wb.Width, wb.Height));
this.pictureBox1.BackgroundImage = bmp;
}
}
希望有所幫助。
這是解析HTML的非常好的庫:
HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("Yor Path(local,web)");
var result=doc.DocumentNode.Descendants("img");//return HtmlCollectionNode
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.