簡體   English   中英

如何從屏幕上拍照?

[英]How can I take a picture from screen?

我想編寫一個程序,將一個PC的屏幕顯示給其他人……類似於演示系統。 如何在當前屏幕上拍照?

.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM