а вот самый кайф
апи винды!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Drawing;
//using System.Drawing.Imaging;
namespace BugReport
{
public class ScreenCapture
{
public System.Drawing.Image CaptureWindow
(IntPtr handle)
{
// get the hDC of the target window
IntPtr hdcSrc = User32.GetWindowDC(handle);
// get the size
User32.RECT windowRect = new User32.RECT();
User32.GetWindowRect(handle, ref windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
// create a device context we can copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy to,
// using getDeviceCaps to get the width/height
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
// select the bitmap object
IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
// restore selection
GDI32.SelectObject(hdcDest, hOld);
// clean up
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
// get a .NET image object for it
System.Drawing.Image img = System.Drawing.Image.FromHbitmap(hBitmap);
// free up the bitmap object
GDI32.DeleteObject(hBitmap);
return img;
}
public System.Drawing.Image CaptureScreen()
{
return CaptureWindow(User32.GetDesktopWindow());
}
public void CaptureWindowToFile
(IntPtr handle,
string filename,
System.Drawing.Imaging.ImageFormat format)
{
System.Drawing.Image img = CaptureWindow(handle);
img.Save(filename, format);
}
public void CaptureScreenToFile
(string filename,
System.Drawing.Imaging.ImageFormat format)
{
System.Drawing.Image img = CaptureScreen();
img.Save(filename, format);
}
}
}