3

次のように、Bitmap オブジェクトからバッファ ポインタを取得できました。

hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);

  // Get Screen Dimensions 

  int         nWidth=GetSystemMetrics(SM_CXSCREEN);
  int         nHeight=GetSystemMetrics(SM_CYSCREEN);

  CImage objCImg;
  objCImg.Create( nWidth, nHeight, 24, BI_RGB);

   HDC hdcMemDC = objCImg.GetDC();

   if(!BitBlt(hdcMemDC,0,0,nWidth, nHeight,hDesktopDC, 0,0,SRCCOPY))
    {
        printf("Error during Bitblt");
    }

   unsigned char* pData = (unsigned char*)objCImg.GetBits();

この pData を使用して画像を変更できます。

画面キャプチャのタイミングを最適化しようとしていますが、この操作にはBitBltが 1 つしか含まれていませんが、PC ではこの操作に 94 ミリ秒かかっています。その間

// Get the Desktop windows handle and device context
hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);

// Get the handle to the existing DC and create a bitmap file object    
HDC         hBmpFileDC=CreateCompatibleDC(hDesktopDC);
HBITMAP     hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);

//    Assign the object in Memory DC to the bitmap and perform a bitblt
  SelectObject(hBmpFileDC,hBmpFileBitmap);
  BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);

  pBuf=malloc(bmpInfo.bmiHeader.biSizeImage); // Size of Image
  GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);   

この操作には、 GetDIBitsで 1 つのBitBlt操作と 1 つのメモリ コピー操作がありますが、この合計操作は PC で 46 ミリ秒かかります。

私の理解によると、BitBltはmemcpy操作にほとんど似ているため、最初のケースでDCが互換DC(CreateCompatibleDC)として派生していないときにbitbltに時間がかかる理由と、2つのBitBlt操作でのこの不一致を誰かが明確にしてください。

また、hdc から直接イメージ バッファ ポインタにアクセスする方法はありますか。これは、HDC から直接画像へのバッファ ポインタを取得できることを意味します。

hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);
// Now derive buffer from this **hDesktopDC**

以前にも同じ質問をしました: Unable to access buffer data

また、Windowsがそのようなタイプのデータ処理を許可している場合、誰かがコメントできますか?

4

0 に答える 0