private Bitmap GetDesktopImage() { //Debug.Log("Thread: " + Thread.CurrentThread.Name); WIN32_API.SIZE size; deskhWnd = WIN32_API.GetDesktopWindow(); IntPtr hDC = WIN32_API.GetDC(deskhWnd); IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC); size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN); size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN); if (m_HBitmap == IntPtr.Zero) { m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy); } if (m_HBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap); WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, WIN32_API.SRCCOPY); WIN32_API.SelectObject(hMemDC, hOld); var a = WIN32_API.DeleteDC(hMemDC); var b = WIN32_API.ReleaseDC(deskhWnd, hDC); var o = System.Drawing.Image.FromHbitmap(m_HBitmap); //Debug.Log(a.ToString() + ":" + b.ToString()); return(o); } return(null); }
/// <summary> /// Função que realiza a captura por meio da API WIN32 /// <returns>Bitmap</returns> /// </summary> public static Bitmap Capture_Desktop_Image() { WIN32_API.SIZE size; IntPtr hDC = WIN32_API.GetDC(WIN32_API.GetDesktopWindow()); IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC); size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN); size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN); m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy); if (m_HBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap); WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, WIN32_API.SRCCOPY); WIN32_API.SelectObject(hMemDC, hOld); WIN32_API.DeleteDC(hMemDC); WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC); return(System.Drawing.Image.FromHbitmap(m_HBitmap)); } return(null); }