2017-09-19 12 views
-1

バッファにあるように画像データを表示するウィンドウに画像を表示したい場合は、CreateDIBForVideoメソッドがmain()のスレッドから呼び出しています。&CaptureBufferCreateDIBSection どこが間違っているのかわからないので、黒いウィンドウが表示されています。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!その型キャスト..しかし、何とか返信いただきありがとうございます、私は以下の私のソリューションを掲載した。 – 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

関連する問題