Screen Capture (CopyFromScreen didn't work fully) [duplicate]

扶醉桌前 提交于 2019-12-13 04:27:03

问题


Possible Duplicate:
How to get screenshot to include the invoking window (on XP)

I'm currently using CopyFromScreen(0, 0, 0, 0, imageSize) to capture the desktop but unfortunately, there is a particular winform's contents which it didn't capture (the rest are alright).

This winform's job is pretty simple; it's just a ticker program. Black background and a label that's moving per millisecond or so, that's all. No borders.

I can't use directx's CaptureScreen (I've tried) because the graphic card's driver doesn't allow me to access the front buffer (there's nothing in the back buffer). I can't use SendKey({PRTSC}) either because I can't overwrite the clipboard's content.

What's interesting however, is that by pressing the keyboard's "Print Screen" and pasting it in MS Paint, the ticker program was captured perfectly. It just didn't work via CopyFromScreen in the code. How do I get it working, or is there any other workaround for this without resorting to win32 APIs?

EDIT:

I have discovered why didn't it work.

It turns out that my ticker program's form had TransparentKey set to anything other than null (maroon in this case). When TransparentKey is not null, CopyFromScreen will not work. It just copies a blank image.

Does anyone knows how to get both (TransparentKey and CopyFromScreen) working together? lol

EDIT 2 (SOLVED):

As posted below, I have discovered that CopyFromScreen is actually a wrapper around BitBlt. Instead of calling CopyFromScreen, I used the BitBlt call here:

How can I save a screenshot directly to a file in Windows?

However, I modified the code a little. Change the call to:

WIN32_API.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC, 0, 0, WIN32_API.SRCCOPY | WIN32_API.CAPTUREBLT);

And add this to WIN32_API class:

public const int CAPTUREBLT = 1073741824 

And now it's possible to capture desktop with TransparentKey.


回答1:


Capture the Screen into a Bitmap or http://www.csharphelp.com/2006/11/capturing-the-screen-image-using-c/ might be of help.



来源:https://stackoverflow.com/questions/14135239/screen-capture-copyfromscreen-didnt-work-fully

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!