开发者

How can I take a picture from screen?

I want to write a program that shows one PC's screen to the others... something like presentation sys开发者_如何转开发tems. how can i take a picture from current screen?


.NET exposes this functionality via the Screen (System.Windows.Forms) class.

     // the surface that we are focusing upon
     Rectangle rect = new Rectangle();

     // capture all screens in Windows
     foreach (Screen screen in Screen.AllScreens)
     {
        // increase the Rectangle to accommodate the bounds of all screens
        rect = Rectangle.Union(rect, screen.Bounds);
     }

     // create a new image that will store the capture
     Bitmap bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);

     using (Graphics g = Graphics.FromImage(bitmap))
     {
        // use GDI+ to copy the contents of the screen into the bitmap
        g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
     }

     // bitmap now has the screen capture
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜