C# 如何获取WPF WebBrowser控件的屏幕截图?
我需要获得在内存中动态下载WPF WebBrowser控件的页面的屏幕截图 基本要求是WPF Webrowser是隐藏的,甚至没有在XAML中实现 有可能吗?如果是,那怎么办 -----解决方案草案------------C# 如何获取WPF WebBrowser控件的屏幕截图?,c#,.net,wpf,C#,.net,Wpf,我需要获得在内存中动态下载WPF WebBrowser控件的页面的屏幕截图 基本要求是WPF Webrowser是隐藏的,甚至没有在XAML中实现 有可能吗?如果是,那怎么办 -----解决方案草案------------ var topLeftCorner = MainBrowser.PointToScreen(new System.Windows.Point(0, 0)); var topLeftGdiPoint = new System.Drawing.Point((int)topLeft
var topLeftCorner = MainBrowser.PointToScreen(new System.Windows.Point(0, 0));
var topLeftGdiPoint = new System.Drawing.Point((int)topLeftCorner.X, (int)topLeftCorner.Y);
var size = new System.Drawing.Size((int)MainBrowser.ActualWidth, (int)MainBrowser.ActualHeight);
Bitmap screenShot = new Bitmap((int)MainBrowser.ActualWidth, (int)MainBrowser.ActualHeight);
using (var graphics = Graphics.FromImage(screenShot))
{
graphics.CopyFromScreen(topLeftGdiPoint, new System.Drawing.Point(),
size, CopyPixelOperation.SourceCopy);
}
screenShot.Save(@"D:\Temp\screenshot.png");
您可以使用安装在PC上的虚拟打印机打印图像
PrintDialog p = new PrintDialog();
p.PrintVisual(webBrowser1,"webBrowser1");
只是一个随机的想法,我想知道如果显示WebBrowser但不在屏幕上lol(我不知道怎么做,但我也想知道怎么做)隐藏/折叠的元素不能作为图形复制到剪贴板内存中,是否会起作用。。。您的屏幕视频缓冲区尚未渲染它,因此您希望如何复制它?
var topLeftCorner = MainBrowser.PointToScreen(new System.Drawing.Point(0, 0));
var topLeftGdiPoint = new System.Drawing.Point((int)topLeftCorner.X, (int)topLeftCorner.Y);
var size = new System.Drawing.Size((int)MainBrowser.ActualWidth, (int)MainBrowser.ActualHeight);
Bitmap screenShot = new Bitmap((int)MainBrowser.ActualWidth, (int)MainBrowser.ActualHeight);
using (var graphics = Graphics.FromImage(screenShot))
{
graphics.CopyFromScreen(topLeftGdiPoint, new System.Drawing.Point(), size, CopyPixelOperation.SourceCopy);
}
screenShot.Save(@"D:\Temp\screenshot.png");