开发者

How can I take a picture from screen?

开发者 https://www.devze.com 2023-01-18 16:47 出处:网络
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 functionalit

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

精彩评论

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