捕捉web浏览器图像

捕捉web浏览器图像

问题描述:

此代码与saveFileDialog捕捉web浏览器图像

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

节省我如何能捕捉Web浏览器的图像后返回一个白色的形象?

+0

非常感谢,它是完美的! – jolly

HTML Agility Pack

这是非常精细库解析HTML:

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

试试这个...

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; 
    } 

} 

希望有所帮助。

+0

谢谢您的回答,但对于代码保存图像? – jolly

+0

你可以在文件中的bmp,​​我刚才在图片框中显示... –

+0

它不工作的图片框是空的和pictureBox1.Image.Save(“webbrowserimage.bmp”,System.Drawing.Imaging.ImageFormat.Bmp) ;返回错误 – jolly