求大神帮忙解答下面的代码是什么意思

.Net技术 码拜 9年前 (2015-05-10) 1018次浏览 0个评论
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern bool BitBlt(int hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop);


        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        private static extern int CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, int lplnitData);


        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        public static extern int DeleteDC(int hdc); 

 private void button1_Click(object sender, EventArgs e)
        {
            int[] fenbianlv = new int[2];
            fenbianlv[0] = Screen.PrimaryScreen.WorkingArea.Width;
            fenbianlv[1] = Screen.PrimaryScreen.WorkingArea.Height;
            int hdlDisplay;
            Graphics gfxDisplay;
            Bitmap bmp;
            Graphics gfxBmp;
            int hdlScreen;
            int hdlBmp;
            hdlDisplay = CreateDC("DISPLAY", null, null, 0);
            gfxDisplay = Graphics.FromHdc((IntPtr)hdlDisplay);
            bmp = new Bitmap(fenbianlv[0], fenbianlv[1], gfxDisplay);
            gfxBmp = Graphics.FromImage(bmp);
            hdlScreen = (int)gfxDisplay.GetHdc();
            hdlBmp = (int)gfxBmp.GetHdc();
            BitBlt(hdlBmp, 0, 0, fenbianlv[0], fenbianlv[1], hdlScreen, 0, 0, 13369376);
            DeleteDC(hdlDisplay);
            gfxDisplay.Dispose();
            gfxBmp.Dispose();
            string path = string.Format( "截图{0}.jpg",k.ToString());
            bmp.Save(path);
            k++;
            MessageBox.Show("截图成功!");
        }

 
实现截图功能代码 看不懂求大神帮忙解释下。谢谢!

40分
截图哪里有这么复杂


        public Bitmap GetScreenBmp(Rectangle rect)
        {
            Bitmap screenBmp = new Bitmap(rect.Width, rect.Height);

            using (Graphics g = Graphics.FromImage(screenBmp))
            {
                g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size);
                Cursor.Current.Draw(g, new Rectangle(Cursor.Position.X, Cursor.Position.Y, 33, 33));
            }
            return screenBmp;
        }

这就实现截屏了
当然Cursor那一句是连当前鼠标样式都画上去了,不想要可以去掉

楼主是用WIN API进行屏幕截屏的。
引用 2 楼 wyd1520 的回复:

楼主是用WIN API进行屏幕截屏的。

代码看不懂,或者有实现此功能更简单的代码吗?

引用 2 楼 wyd1520 的回复:

楼主是用WIN API进行屏幕截屏的。

API相比CopyFromScreen有什么好处吗?
反正我是能不用API就尽量不用


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求大神帮忙解答下面的代码是什么意思
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!