.Net 擷取螢幕 Print Screen 螢幕畫面功能 .Net 擷取螢幕 Print Screen 螢幕畫面功能
  .NET       ez      2012-04-18

透過 Graphics 中的 CopyFromScreen 即可達到複製螢幕功能!

全螢幕擷取到檔案:

            Bitmap myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics g = Graphics.FromImage(myImage);
            g.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
            IntPtr dc1 = g.GetHdc();
            g.ReleaseHdc(dc1);
            myImage.Save(@"c:\screen.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

視窗畫面擷取到檔案:

            Bitmap myImage = new Bitmap(this.Width, this.Height);
            Graphics g = Graphics.FromImage(myImage);
            g.CopyFromScreen(new Point(this.Location.X, this.Location.Y), new Point(0, 0), new Size(this.Width, this.Height));
            IntPtr dc1 = g.GetHdc();
            g.ReleaseHdc(dc1);
            myImage.Save(@"c:\screen.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

標籤:   .NET、  CopyFromScreen、  Graphics

我要留言