리눅스맨

C# 스크린샷 캡쳐할때 사용함수

※ 위 배너를 클릭하면 1달러에 (900원~1800원) 살 수 있는 가성비 레어템 많습니다.

출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=18&MAEULNO=8&no=2010&page=2

 

 

[[DllImport(“gdi32.dll”)]
static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int
wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
[DllImport(“user32.dll”)]
static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport(“gdi32.dll”)]
static extern IntPtr DeleteDC(IntPtr hDc);
[DllImport(“gdi32.dll”)]
static extern IntPtr DeleteObject(IntPtr hDc);
[DllImport(“gdi32.dll”)]
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport(“gdi32.dll”)]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport(“gdi32.dll”)]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
[DllImport(“user32.dll”)]
public static extern IntPtr GetDC(IntPtr ptr);
private Bitmap CaptureScreen(int x, int y, int 넓이, int 높이)
{
IntPtr hDC = GetDC(IntPtr.Zero);
IntPtr hMemDC = CreateCompatibleDC(hDC);
IntPtr hBitmap = CreateCompatibleBitmap(hDC, 넓이, 높이);
IntPtr hOld = (IntPtr)SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, -x, -y, 넓이+x, 높이+y, hDC, 0, 0, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
SelectObject(hMemDC, hOld);
DeleteDC(hMemDC);
ReleaseDC(IntPtr.Zero, hDC);
Bitmap memoryImage = System.Drawing.Image.FromHbitmap(hBitmap);
DeleteObject(hBitmap);
return memoryImage;
}

게시됨

카테고리

작성자

태그: