如何从屏幕上拍照?

时间:2010-09-30 02:54:12

标签: c# screen screen-capture

我想写一个程序,向其他人显示一个PC的屏幕......就像演示系统一样。如何从当前屏幕拍照?

1 个答案:

答案 0 :(得分:2)

.NET通过Screen( System.Windows.Forms )类公开此功能。

     // 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