/// <summary> /// Takes the snapshot of the Desktop /// </summary> /// <returns>Bitmap object</returns> public static Bitmap DesktopSnapshot() { IntPtr hwnd = USER32.GetShellWindow(); if (hwnd == IntPtr.Zero) { return(null); } else { USER32.RECT rc; USER32.GetWindowRect(hwnd, out rc); Rectangle r = ApiConverter.ToRectangle(rc); Bitmap bitmap = new Bitmap(r.Width, r.Height, PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(bitmap)) { IntPtr hdcBitmap = g.GetHdc(); USER32.PrintWindow(hwnd, hdcBitmap, 0); } return(bitmap); } }