Exemplo n.º 1
0
        /// <summary>
        /// 获得窗体屏幕图片(此方法有宽度和分辨率不正确性)
        /// </summary>
        public Bitmap GetScreenData()
        {
            windowshandle.Rect rect  = new windowshandle.Rect();
            Bitmap             QQPic = new Bitmap(1, 1);

            if (!hwnd.Equals(IntPtr.Zero))
            {
                windowshandle.GetWindowRect(hwnd, ref rect);  //获得目标窗体的大小
                QQPic = new Bitmap(rect.Right - rect.Left + 300, rect.Bottom - rect.Top + 150);
                Graphics g1   = Graphics.FromImage(QQPic);
                IntPtr   hdc1 = windowshandle.GetDC(hwnd);
                IntPtr   hdc2 = g1.GetHdc(); //得到Bitmap的DC
                windowshandle.BitBlt(hdc2, 0, 0, rect.Right - rect.Left + 300, rect.Bottom - rect.Top + 150, hdc1, 0, 0, windowshandle.SRCCOPY);
                g1.ReleaseHdc(hdc2);         //释放掉Bitmap的DC
            }
            return(QQPic);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 截取指定窗口
        /// </summary>
        /// <returns></returns>
        public Bitmap GetRunAPPImage()
        {
            windowshandle.Rect rect = new windowshandle.Rect();
            Image img;

            try
            {
                windowshandle.GetWindowRect(hwnd, ref rect); //取控件的矩形
                img = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top);
                Graphics g = Graphics.FromImage(img);
                g.CopyFromScreen(rect.Left, rect.Top, 0, 0, Screen.FromHandle(hwnd).Bounds.Size);
                return(new Bitmap(img));
            }
            catch (Exception ex)
            {
                MessageBox.Show("出错:" + ex);
            }
            return(null);
        }