http://teststack.github.com/White/에서 처리 할 수있는 API가 있습니까? 찾을 수없는 것 같습니다. GitHub의에 코드를 찾고에서흰색으로 전체 화면의 스크린 샷을 찍는 방법이 있습니까?
감사
파블
http://teststack.github.com/White/에서 처리 할 수있는 API가 있습니까? 찾을 수없는 것 같습니다. GitHub의에 코드를 찾고에서흰색으로 전체 화면의 스크린 샷을 찍는 방법이 있습니까?
감사
파블
White.Repository 프로젝트는 실제로 스크린 샷과 함께 테스트 흐름을 기록하지만 아직 문서화되지 않았으며 NuGet에서 아직 발표되지 않았습니다 (곧 예정).
개인적으로 나는이 클래스를 여러 소스에서 모아서 원래 가지고있는 위치를 잊어 버립니다. 이것은 모달 대화 상자와 다른 많은 구현체가 어떤 이유로 캡처하지 못한 다른 것들을 포착합니다.
/// <summary>
/// Provides functions to capture the entire screen, or a particular window, and save it to a file.
/// </summary>
public class ScreenCapture
{
[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 GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr ptr);
public Bitmap CaptureScreenShot()
{
var sz = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size;
var hDesk = GetDesktopWindow();
var hSrce = GetWindowDC(hDesk);
var hDest = CreateCompatibleDC(hSrce);
var hBmp = CreateCompatibleBitmap(hSrce, sz.Width, sz.Height);
var hOldBmp = SelectObject(hDest, hBmp);
BitBlt(hDest, 0, 0, sz.Width, sz.Height, hSrce, 0, 0, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
var bmp = Image.FromHbitmap(hBmp);
SelectObject(hDest, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hDest);
ReleaseDC(hDesk, hSrce);
return bmp;
}
}
그런 다음 나는 이것이 아주 오래된 게시물입니다 알고
var sc = new ScreenCapture();
var bitmap = sc.CaptureScreenShot();
bitmap.Save(fileName + ".png"), ImageFormat.Png);
는, 그에 대한 API가 표시되지 않습니다 (아마 add it as a feature request을?).
클래스와 Graphics.CopyFromScreen
의 조합을 사용하면 상당히 간단하게 처리 할 수 있습니다. this question에 대한 응답에서 화면 또는 활성 창을 캡처하는 방법에 대한 몇 가지 예가 있습니다.
소비합니다. 그러나 나는 그것을 업데이트하는 것을 상처 입을 수는 없다. TestStack.White는 이제 다음과 같은 기능을 제공합니다 :
//Takes a screenshot of the entire desktop, and saves it to disk
Desktop.TakeScreenshot("C:\\white-framework.png", System.Drawing.Imaging.ImageFormat.Png);
//Captures a screenshot of the entire desktop, and returns the bitmap
Bitmap bitmap = Desktop.CaptureScreenshot();