以编程方式截取网页截图

Man*_*ish 15 .net c# screenshot webpage-screenshot

如果输入URL,如何以编程方式拍摄网页的情景?

这就是我现在所拥有的:

// The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap)
Bitmap bitmap = new Bitmap(1024, 768);
Rectangle bitmapRect = new Rectangle(0, 0, 1024, 768);
// This is a method of the WebBrowser control, and the most important part
webBrowser1.DrawToBitmap(bitmap, bitmapRect);

// Generate a thumbnail of the screenshot (optional)
System.Drawing.Image origImage = bitmap;
System.Drawing.Image origThumbnail = new Bitmap(120, 90, origImage.PixelFormat);

Graphics oGraphic = Graphics.FromImage(origThumbnail);
oGraphic.CompositingQuality = CompositingQuality.HighQuality;
oGraphic.SmoothingMode = SmoothingMode.HighQuality;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle oRectangle = new Rectangle(0, 0, 120, 90);
oGraphic.DrawImage(origImage, oRectangle);

// Save the file in PNG format
origThumbnail.Save(@"d:\Screenshot.png", ImageFormat.Png);
origImage.Dispose();
Run Code Online (Sandbox Code Playgroud)

但这不起作用.它只给我一张白色的空白图片.我在这里错过了什么?

有没有其他方法可以编程方式获取网页的屏幕截图?

Man*_*ish 7

我搜索并搜索并搜索了网页缩略图(The Code Project文章).

  • 这使用Microsofts Web浏览器控件,它经常为您提供空白的白色屏幕截图 (2认同)