2017-09-19 1 views
-1

이미지를 버퍼에 넣는 것처럼 이미지를 표시하고 싶습니다. CreateDIBForVideo 메서드가 &CaptureBuffer에서 CreateDIBSection으로 main()의 스레드에서 호출하고 있습니다. 어디가 잘못되어 검은 색 창이 보이는지 모릅니다.CreateDIBSection을 사용하여 이미지를 표시하는 방법

void CreateDIBForVideo() 
{ 
    // ScreenCaptureProcessorGDI is a class it have initialization for capture window screen 
    screenObject = new ScreenCaptureProcessorGDI(); 
    screenObject->init(); 

    HDC DisplayDC = CreateDC((LPCWSTR)"DISPLAY", NULL, NULL, NULL); 

    BITMAPINFO bmpInfo = { 0 }; 
    bmpInfo.bmiHeader.biSize= sizeof(BITMAPINFOHEADER); 
    bmpInfo.bmiHeader.biWidth = screenObject->lOutputDuplDesc.ModeDesc.Width; 
    bmpInfo.bmiHeader.biHeight= screenObject->lOutputDuplDesc.ModeDesc.Height; 
    bmpInfo.bmiHeader.biPlanes = 1; 
    bmpInfo.bmiHeader.biBitCount = 32; 
    bmpInfo.bmiHeader.biCompression = BI_RGB; 
    bmpInfo.bmiHeader.biSizeImage = (4 * screenObject->lOutputDuplDesc.ModeDesc.Width * screenObject->lOutputDuplDesc.ModeDesc.Height); 
    bmpInfo.bmiHeader.biXPelsPerMeter = 0; 
    bmpInfo.bmiHeader.biYPelsPerMeter = 0; 
    bmpInfo.bmiHeader.biClrUsed = 0; 
    bmpInfo.bmiHeader.biClrImportant = 0; 

    CaptureBuffer = NULL; 
    HDC pXorDC = CreateCompatibleDC(DisplayDC); 
    HBITMAP hXorDib = CreateDIBSection(DisplayDC, &bmpInfo, DIB_RGB_COLORS, (void**)&CaptureBuffer, NULL, 0); 

    hXorTemp = (HBITMAP)SelectObject(pXorDC, hXorDib); 
    // startGrab this thread capture a windows screen after init() 
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&startGrab, NULL, 0, NULL); 
} 


void startGrab() 
{ 
    for (int index = 0; index < 100; index++) 
    { 
     // grabImage will capture window screen and send image as a buffer to `CaptureBuffer` 
     screenObject->grabImage();  
     PaintViewerWindow(); 
     UpdateWindow(global_hWnd); 
     ::Sleep(2000); 
    } 
} 

void PaintViewerWindow() 
{ 
    HDC paintDC; 
    PAINTSTRUCT ps; 
    paintDC = BeginPaint(global_hWnd, &ps); 
    SetStretchBltMode(paintDC, HALFTONE);  
    BitBlt(paintDC, 0, 0, 1366, 768, pXorDC, 0, 0, SRCCOPY);   
    EndPaint(global_hWnd, &ps); 

} 
+2

그 (LPCWSTR) 캐스트는 큰 실수입니다. 오류 검사도 없으므로 거기에서 블랙홀로 나선형이됩니다. –

+0

@HansPassant Nop! 그것의 typecasting ..하지만 어쨌든 회신을 주셔서 감사합니다, 나는 아래 내 솔루션을 게시했습니다. – Krish

+0

잘못된 전송입니다. 넓은 끈을 원한다면 하나 만들어라. 'L "Wide String"'맹목적으로 맹목적으로 무언가를 캐스팅 할 수 있다고해서 마술처럼 옳은 것은 아닙니다. –

답변

0

나는 지금 내가이 이제 제대로 작동 char *DisplayBufferUCHAR *CaptureBuffer 복사로 변경 때문에 UCHAR *CaptureBuffer 오전 직접 CreateDIBSectionCaptureBuffer을 통과하는 위의 문제 그것은에 대한 해결책을 찾을 수 있습니다.

 UCHAR *CaptureBuffer = NULL; 
     char *DisplayBuffer = NULL; 
     long CaptureSize = NULL; 

     void saveImage(unsigned int frame_num, BITMAPINFO &lBmpInfo, std::unique_ptr<BYTE> pBuf, UCHAR* &CaptureBuffer, long &CaptureSize) 
      { 

        BITMAPFILEHEADER bmpFileHeader; 

        bmpFileHeader.bfReserved1 = 0; 
        bmpFileHeader.bfReserved2 = 0; 
        bmpFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + lBmpInfo.bmiHeader.biSizeImage; 
        bmpFileHeader.bfType = 'MB'; 
        bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 

        CaptureSize = lBmpInfo.bmiHeader.biSizeImage; 
        CaptureBuffer = (UCHAR*)malloc(CaptureSize); 

        memcpy(CaptureBuffer, pBuf.get(), lBmpInfo.bmiHeader.biSizeImage);   
        //Here am copying CaptureBuffer(uchar) to DisplayBuffer(char) 
        memcpy(DisplayBuffer, CaptureBuffer, CaptureSize); 
        lresult = 0; 

      } 

    void CreateDIBForVideo() 
{ 
    // ScreenCaptureProcessorGDI is a class it have initialization for capture window screen 
    screenObject = new ScreenCaptureProcessorGDI(); 
    screenObject->init(); 

    HDC DisplayDC = CreateDC((LPCWSTR)"DISPLAY", NULL, NULL, NULL); 

    BITMAPINFO bmpInfo = { 0 }; 
    bmpInfo.bmiHeader.biSize= sizeof(BITMAPINFOHEADER); 
    bmpInfo.bmiHeader.biWidth = screenObject->lOutputDuplDesc.ModeDesc.Width; 
    bmpInfo.bmiHeader.biHeight= screenObject->lOutputDuplDesc.ModeDesc.Height; 
    bmpInfo.bmiHeader.biPlanes = 1; 
    bmpInfo.bmiHeader.biBitCount = 32; 
    bmpInfo.bmiHeader.biCompression = BI_RGB; 
    bmpInfo.bmiHeader.biSizeImage = (4 * screenObject->lOutputDuplDesc.ModeDesc.Width * screenObject->lOutputDuplDesc.ModeDesc.Height); 
    bmpInfo.bmiHeader.biXPelsPerMeter = 0; 
    bmpInfo.bmiHeader.biYPelsPerMeter = 0; 
    bmpInfo.bmiHeader.biClrUsed = 0; 
    bmpInfo.bmiHeader.biClrImportant = 0; 

    CaptureBuffer = NULL; 
    HDC pXorDC = CreateCompatibleDC(DisplayDC); 
    HBITMAP hXorDib = CreateDIBSection(DisplayDC, &bmpInfo, DIB_RGB_COLORS, (void**)&DisplayBuffer, NULL, 0); 

    hXorTemp = (HBITMAP)SelectObject(pXorDC, hXorDib); 
    // startGrab this thread capture a windows screen after init() 
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&startGrab, NULL, 0, NULL); 
} 
+1

아, 사고에 의한 프로그래밍 ... –

+0

@RetiredNinja는 사과드립니다. C++에 익숙하지 않습니다. 여기에 게시 된 코드의 일부 장소에 갇혀 있지만 아무도 응답하지 않았으며 자신으로부터 해결책을 찾고 게시했습니다 ... 부정적입니다. 그것에 대해 생각하는 내 게시물에 투표 .... – Krish

관련 문제