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,此操作在我的 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中有一个BitBlt和一个内存复制操作,但在我的 PC 上,这个总操作仍需要 46 毫秒。

有人可以澄清一下两个 BitBlt 操作中的这种差异,以及为什么在第一种情况下 DC 不是作为兼容 DC (CreateCompatibleDC) 派生时 bitblt 需要更多时间,因为根据我的理解,BitBlt 几乎类似于memcpy操作。

反过来我还想问有没有办法直接从hdc访问图像缓冲区指针。这意味着可以直接从 HDC 获取指向图像的缓冲区指针

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

我之前也问过同样的问题:无法访问缓冲区数据

另外,如果windows允许这种类型的数据处理,有人可以评论吗?

4

0 回答 0