I get the screenshot of a webpage contained inside a WebBrowser control just as described here and here, but I have a problem: if the WebBrowser control is not at full screen, the screenshot gets cropped to the size of the control.
Is it possible to save a screenshot of the whole page if the WebBrowser control is not at full screen?
This is the code I'm currently using to save the screenshot:
private void SaveBrowserScreenshot(WebBrowser browser, string path, string name)
{
const int width = 1024;
const int height = 768;
const string extension = ".png";
using (var bitmap = new Bitmap(width, height))
{
var rect = new Rectangle(0, 0, width, height);
browser.DrawToBitmap(bitmap, rect);
using (var image = bitmap)
{
using (var graphic = Graphics.FromImage(image))
{
graphic.CompositingQuality = CompositingQuality.HighQuality;
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
image.Save(String.Concat(path, "\\", name, extension), ImageFormat.Png);
}
}
}
}
Performance is not an issue since this will never be used in production.
Could you make a button that when it takes the snapshot it takes the current URL and puts that into a new WeBrowser object which is then expanded to a much bigger size so when it takes the screenshot it's full size?