CopyFromScreen截屏


传统截屏
#region 导入函数
      
        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateDC(string lpszDriver, string lpszDrivse, string lpszOutput, Int32 lpInitData);


        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateCompatibleDC(IntPtr hdc);


        [DllImport("gdi32.dll")]
        private static extern int GetDeviceCaps(IntPtr hdc, Int32 nIndex);


        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);


        [DllImport("gdi32.dll")]
        private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);


        [DllImport("gdi32.dll")]
        private static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest,
                 int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, UInt32 dwRop);


        [DllImport("gdi32.dll")]
        private static extern int DeleteDC(IntPtr hdc);


        #endregion


 现在截屏简单多了


 Console.WriteLine(DateTime.Now.Millisecond.ToString());
            System.Drawing.Bitmap photo = new System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(photo);
            graphic.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
            photo.Save(@”r:\aa.jpg”, System.Drawing.Imaging.ImageFormat.Jpeg);
            Console.WriteLine(DateTime.Now.Millisecond.ToString());


CopyFromScreen 方法对于将一个图像放置于另一个图像顶部非常有用。若要指定源颜色和目标颜色的混合方式,请使用 CopyFromScreen 方法之一,该方法采用 CopyPixelOperation 参数。

历史博文

标签:,
九月 14, 2009 at 11:58 下午 by yippee 55 次
Category: Dev
Tags: ,