Esempio n. 1
0
        /// <summary>
        /// 截取窗体图
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public Bitmap GetFormFace(System.Windows.Forms.Form f)
        {
            IntPtr   windc  = f.Handle;
            Graphics g1     = Graphics.FromHwnd(windc);
            Bitmap   mimage = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, g1);
            Graphics g2     = Graphics.FromImage(mimage);
            IntPtr   dc1    = g1.GetHdc();
            IntPtr   dc2    = g2.GetHdc();

            GDIAPI.BitBlt(dc2, 0, 0, mimage.Width, mimage.Height, dc1, 0, 0, 13369376);
            g1.ReleaseHdc(dc1);
            g2.ReleaseHdc(dc2);

            g1.Dispose();
            g2.Dispose();
            GC.Collect();
            return(mimage);
        }
Esempio n. 2
0
        /// <summary>
        /// 通过系统API截取全屏图像
        /// </summary>
        /// <returns></returns>
        public Bitmap GetFullScreenByApi()
        {
            //方法三
            IntPtr windc = GDIAPI.CreateDC("DISPLAY", null, null, IntPtr.Zero);
            //Graphics g1 = Graphics.FromHdc(windc);
            var      mimage = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            Graphics g2     = Graphics.FromImage(mimage);
            //IntPtr dc1 = g1.GetHdc();
            IntPtr dc2 = g2.GetHdc();

            GDIAPI.BitBlt(dc2, 0, 0, mimage.Width, mimage.Height, windc, 0, 0, 13369376);
            //g1.ReleaseHdc(dc1);
            g2.ReleaseHdc(dc2);
            //try
            //{
            //    GDIAPI.ReleaseDC(windc);
            //}
            //catch
            //{ }
            //g1.Dispose();
            g2.Dispose();

            return(mimage);
        }