Csharp/C#教程:捕获WebBrowser图像分享


捕获WebBrowser图像

使用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(); } 

我如何捕获网络浏览器的图像?

看看这里显示的代码https://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx

试试这个 …

 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敏捷包

这是解析HTML的非常好的库:

上述就是C#学习教程:捕获WebBrowser图像分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = web.Load("Yor Path(local,web)"); var result=doc.DocumentNode.Descendants("img");//return HtmlCollectionNode 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/961919.html

(0)
上一篇 2021年11月26日
下一篇 2021年11月26日

精彩推荐