使用C#拍摄任何外部应用程序的屏幕截图 [英] Take screenshot of any external application using C#

查看:243
本文介绍了使用C#拍摄任何外部应用程序的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个C#(WPF)应用程序,我们想要在其中截取由我们启动的任意应用程序的屏幕快照(即,因此我们引用了我们启动的流程)。
该应用程序可能会最小化或位于其他窗口之后,但我们仍然只希望单个应用程序的图像,而不希望重叠像素。

We have a C# (WPF) application in which we want to take a screenshot of an arbitrary application launched by us (i.e. so we have a reference to the Process we started). The application may be minimized or behind other windows but we still only want the image of the individual application, not overlapping pixels.

我知道使用BitBlt或 PrintWindow 大部分时间都可以工作,但是在处理直接绘制到图形设备上的DirectX或OpenGL应用程序时,它们会失败(我只能得到黑色/透明像素)。我已经在拍摄以下内容的文章 C#的Direct3D应用程序,所以我想我已经解决了这种情况。

I know the typical P/Invoke solutions using BitBlt or PrintWindow work most of the time, but those fail (I only get black/transparent pixels) when dealing with an DirectX or OpenGL application that draws directly to the graphics device. I have found this article on taking a screenshot of a Direct3D app from C#, so I think I have that case covered.

所以我的问题是这样:


  1. 对于OpenGL应用程序我该怎么做?

  2. 确定适当的使用方法(PW / DX / GL)的最简单方法是什么?

  3. 是否有一种通用的方法?

对于#2,我是否被降级为检查可执行文件加载的模块,并查看是否已加载DirectX或OpenGL DLL /程序集?

For #2, am I relegated to inspecting the modules loaded by the executable and seeing if an DirectX or OpenGL DLL/Assembly is loaded?

这只能在Windows XP上运行(不是跨平台的,不是

This only has to run on Windows XP (not cross-platform and not going to Vista/7 anytime soon if ever for this application).

推荐答案

答案1:在OpenGL中,您可以调用glReadBuffer和glReadPixels获取屏幕位图。但是,这很慢(因此您不会在每一帧重复调用它),并且当GL窗口与另一个应用程序/窗口重叠时,您也可能会遇到问题。正确的方法是使用 pbuffer

Answer to 1: In OpenGL, you can call glReadBuffer and glReadPixels to get the screen bitmap. However, this is slow (so you don't call it repeatedly every frame) and you might also have problems when th GL window is overlapped by another application / window. The correct way to do this is to "render to texture" (google it) by using a pbuffer.

第2点的想法:如果您有窗口句柄,则可以获取 pixelformatdescriptor 结构并进行检查。从来没有尝试过。

Idea for 2: If you have the handle to window, you might be able to get the pixelformatdescriptor structure it has and check it. Never tried it though.

对于3:顺便说一句,我认为没有任何通用的方法可以做到这一点。

For 3: By the way, I don't think there is a single universal way of doing this without any problems..

这篇关于使用C#拍摄任何外部应用程序的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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