简体   繁体   English

仅录制一个窗口的视频

[英]Recording video of only one Window

I need to capture my screen as a video, for that I used Expression Encoder 4, but in my application I also need to capture one single window, but I can't find a way of doing it, with EE4 I tried changing dynamically the CaptureRectangle of my ScreenCaptureJob , but that doesn't seem to be possible. 我需要将我的屏幕捕获为视频,因为我使用了Expression Encoder 4,但在我的应用程序中我还需要捕获一个窗口,但是我找不到这样做的方法,使用EE4我尝试动态更改我的ScreenCaptureJob的 CaptureRectangle ,但似乎不可能。 So my question is, do you know anyway of doing this 'single window capture' using preferably C# or maybe C++? 所以我的问题是,您是否知道使用C#或C ++进行“单窗口捕获”?

You could get the window handle of the window that you're interested in, set a timer, and at each timer tick capture that window's contents. 可以得到你感兴趣的窗口的窗口句柄,设置一个计时器,并在每个计时器滴答捕获该窗口的内容。 Doing so is non-trivial, but certainly possible. 这样做并非易事,但肯定是可能的。 I did it in C many years ago, but that code is long gone. 我多年前在C中做过,但代码早已不复存在。

The problem is simpler if you just want to capture a rectangular area of the screen. 如果您只想捕获屏幕的矩形区域,问题就更简单了。 You can get the window handle, query its size and position, and then copy that area from the screen. 您可以获取窗口句柄,查询其大小和位置,然后从屏幕复制该区域。 In C or C++, you would get the desktop DC and copy bits from it. 在C或C ++中,您将获得桌面DC并从中复制位。 In C#, you could create a Bitmap that's the size of the window, call Graphics.FromImage to get a Graphics object for the image, and then call CopyFromScreen to get the window contents. 在C#中,您可以创建一个与窗口大小相同的Bitmap ,调用Graphics.FromImage获取图像的Graphics对象,然后调用CopyFromScreen来获取窗口内容。 The drawback is that this only works if nothing is covering the window in question. 缺点是这只有在没有任何东西覆盖有问题的窗口时才有效。 If something is covering any part of the window, you're going to capture that. 如果有什么东西覆盖了窗户的任何部分,你就会捕捉到它。

In any case, you end up with a stream of images that you need to combine into a video. 无论如何,您最终会得到一组需要合并为视频的图像。 There are a number of libraries that will do that. 有许多库可以做到这一点。 For a C# solution, you might start by looking at create video from streamed images c# . 对于C#解决方案,您可以从流式映像c#查看创建视频开始。 I suspect there are similar libraries for C++. 我怀疑有类似的C ++库。 There are also some command line tools that will do it, although my experience with them has been less than satisfactory. 虽然我对它们的经验不尽如人意,但也有一些命令行工具可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM