2012-09-06 2 views
3

내 VS2008, MFC, C++ 프로젝트에서 창 내용 (클라이언트 영역)을 캡처하고 싶습니다. 나는 또한 다음 코드를 사용하여 윈도우의 내용을 블리트 시도 How to get screenshot of a window as bitmap object in C++?OpenGL/Direct3D 타사 응용 프로그램 캡쳐 화면

:

void captureWindow(int winId) 
{ 
HDC handle(::GetDC(HWND(winId))); 
CDC sourceContext; 
CBitmap bm; 
CDC destContext; 

if(!sourceContext.Attach(handle)) 
{ 
    printf("Failed to attach to window\n"); 
    goto cleanup; 
} 

RECT winRect; 
sourceContext.GetWindow()->GetWindowRect(&winRect); 
int width = winRect.right-winRect.left; 
int height = winRect.bottom-winRect.top; 

destContext.CreateCompatibleDC(&sourceContext); 

if(!bm.CreateCompatibleBitmap(&sourceContext, width, height)) { 
    printf("Failed to create bm\n"); 
    goto cleanup; 
} 

{ 
    //show a message in the window to enable us to visually confirm we got the right window 
    CRect rcText(0, 0, 0 ,0); 
    CPen pen(PS_SOLID, 5, 0x00ffff); 
    sourceContext.SelectObject(&pen); 
    const char *msg = "Window Captured!"; 
    sourceContext.DrawText(msg, &rcText, DT_CALCRECT); 
    sourceContext.DrawText(msg, &rcText, DT_CENTER); 

    HGDIOBJ hOldDest = destContext.SelectObject(bm); 
    if(hOldDest==NULL) 
    { 
     printf("SelectObject failed with error %d\n", GetLastError()); 
     goto cleanup; 
    } 

    if (!destContext.BitBlt(0, 0, width, height, &sourceContext, 0, 0, SRCCOPY)){ 
     printf("Failed to blit\n"); 
     goto cleanup; 
    } 

    //assume this function saves the bitmap to a file 
    saveImage(bm, "capture.bmp"); 

    destContext.SelectObject(hOldDest); 
} 
cleanup: 
    destContext.DeleteDC(); 
    sourceContext.Detach(); 
    ::ReleaseDC(0, handle); 
} 

코드는 대부분의 애플리케이션에 잘 작동 나는 여기에서 설명한에서 PrintWindow 기술을 사용하여 시도했다. 그러나 스크린 샷을 캡처해야하는 특정 응용 프로그램에는 OpenGl 또는 Direct3D를 사용하여 렌더링 된 것으로 생각되는 창이 있습니다. 두 가지 방법 모두 앱의 대부분을 잘 캡처 할 수 있지만 '3D'영역은 검은 색이나 왜곡 된 상태로 남습니다.

응용 프로그램 코드에 액세스 할 수 없으므로 어떤 식 으로든 변경할 수 없습니다.

"3d"창을 포함하여 모든 내용을 캡처 할 수있는 방법이 있습니까?

+0

동일한 문제가 발생했습니다. 해결책을 찾은 경우 게시하십시오. –

+0

불행히도 나는 이것을 해결할 수 없었다. 그것은 우리 시스템에 버그로 남아 있습니다 :-( – Vanvid

답변

0

3D 영역의 데이터는 그래픽 퍼널 아래로 그래픽 어댑터에 의해 생성되며 응용 프로그램에서 렌더링 컨텍스트에서 바이트 데이터를 읽지 못할 수 있습니다. OpenGL에서 glReadPixels()을 사용하여 데이터를 퍼널에서 애플리케이션 메모리로 다시 가져올 수 있습니다. 사용법은 여기를 참조하십시오. http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml

관련 문제