如何以编程方式将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();
但是,这是行不通的。它只给我一张白色的空白图片。我在这里错过了什么?
是否有任何其他方式我可以以编程方式获取网页的屏幕截图?
昨天刚刚问了这个问题,虽然主要针对Perl。也许一些答案会帮助你,虽然显然会带你另一个方向。这里是[链接](http://stackoverflow.com/questions/2312852/how-can-i-take-screenshots-with-perl)。 – lundmark 2010-02-23 21:49:54