Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取WPF WebBrowser控件的屏幕截图?_C#_.net_Wpf - Fatal编程技术网

C# 如何获取WPF WebBrowser控件的屏幕截图?

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

我需要获得在内存中动态下载WPF WebBrowser控件的页面的屏幕截图

基本要求是WPF Webrowser是隐藏的,甚至没有在XAML中实现

有可能吗?如果是,那怎么办

-----解决方案草案------------

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");