如何获得WPF Webrowser控制的屏幕截图? [英] How to get Screenshot of WPF Webrowser Control?

查看:178
本文介绍了如何获得WPF Webrowser控制的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到它下载WPF Webrowser控制飞在内存中的页面的截图

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

是否有可能呢?如果是的话怎么办?

-------- DRAFT解决方案-----------

  VAR topLeftCorner = MainBrowser.PointToScreen(新System.Windows.Point(0,0));
VAR topLeftGdiPoint =新System.Drawing.Point((INT)topLeftCorner.X,(INT)topLeftCorner.Y);
VAR大小=新System.Drawing.Size((INT)MainBrowser.ActualWidth,(INT)MainBrowser.ActualHeight);

位图的截图=新位图((INT)MainBrowser.ActualWidth,(INT)MainBrowser.ActualHeight);

使用(VAR图形= Graphics.FromImage(截图))
{
   graphics.CopyFromScreen(topLeftGdiPoint,新System.Drawing.Point()
        大小,CopyPixelOperation.SourceCopy);
}

screenShot.Save(@D:\ TEMP \ screenshot.png);
 

解决方案

作为一种理念,你可以使用安装在PC上的虚拟打印机和打印的图像。

  PrintDialog类P =新PrintDialog类();
p.PrintVisu​​al(webBrowser1webBrowser1);
 

I need to get a screenshot of the page which downloads WPF Webrowser Control on fly in memory.

The basic requirement is the WPF Webrowser is hidden or even doesn't implemented in XAML.

Is it possible to do? If yes then how?

-------- DRAFT SOLUTION -----------

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

解决方案

As an idea you can use a virtual printer installed on your PC and print as image.

PrintDialog p = new PrintDialog();
p.PrintVisual(webBrowser1,"webBrowser1");

这篇关于如何获得WPF Webrowser控制的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆