How do I get access to an image of the desktop buffer in .NET?
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);
精彩评论