开发者

How do I get access to an image of the desktop buffer in .NET?

开发者 https://www.devze.com 2022-12-15 08:55 出处:网络
I am making a very simple app in C# with Visual Studio, so I\'m using that Forms package. I need to get access to an image of everything below it, so that开发者_StackOverflow I can manipulate the imag

I am making a very simple app in C# with Visual Studio, so I'm using that Forms package. I need to get access to an image of everything below it, so that开发者_StackOverflow I can manipulate the image. How can I do this?

It doesn't have to be real time very much, since I'll probably be polling it not more than say 10fps.


You could use Graphics.CopyFromScreen, but you will need to hide your window before you call it or otherwise it will appear in the image.


You can use Interop to get a hook to the "Desktop Window", if that's what you mean, and then you can use that to get your screenshot...this link might help:

Getting the Desktop Window from .NET

Another option (you said WinForms, right) is to create a placeholder Bitmap and use the Graphics.CopyFromScreen method:

int screenWidth = 1024;
int screenHeight = 768;
Bitmap holder = new Bitmap(screenWidth, screenHeight);
Graphics graphics = Graphics.FromImage(holder);
graphics.CopyFromScreen(0,0,0,0,new Size(screenWidth, screenHeight), CopyPixelOperation.SourceCopy);
0

精彩评论

暂无评论...
验证码 换一张
取 消