private void WebsiteScreenshot( string url, string file) { //Create a webbrwoser object WebBrowser browser = new WebBrowser(); //Deactivate scrollbars, unless you want them to //appear on your screenshot browser.ScrollBarsEnabled = false ; //Suppress (java-)script error popups browser.ScriptErrorsSuppressed = true ; //Open the given url in webbrowser browser.Navigate( new Uri(url)); //Wait until the page is fully loaded while (browser.Document == null || browser.Document.Body == null ) Application.DoEvents(); //Resize the webbrowser object to the same size as the //webpage Rectangle websiteSize = browser.Document.Body.ScrollRectangle; browser.Size = new Size(websiteSize.Width,websiteSize.Height); //Create a bitmap object with the same dimensions as the website Bitmap bmp = new Bitmap(websiteSize.Width, websiteSize.Height); //Paint the website contents to the bitmap browser.DrawToBitmap(bmp, new Rectangle(0, 0, websiteSize.Width, websiteSize.Height)); browser.Dispose(); //Save the bitmap at the given filepath bmp.Save(file, ImageFormat.Png); } |
You can then call the method as follows:
1
2
3
| //If you want file extension than .png, don't forget to change the //ImageFormat-type in the above main function! |
Hiç yorum yok:
Yorum Gönder