Directshow抓图

   1: //Capture bitmap form directshow by IVMRWindowlessControl9 interface
   2: HRESULT CaptureBitmap(IVMRWindowlessControl9 *pVMRControl9, int destWidth, int destHeight, LPCWSTR fileName)
   3: {
   4:     BYTE* pDib = NULL;
   5:     HRESULT hr = pVMRControl9->GetCurrentImage(&pDib);
   6:     if (FAILED(hr))
   7:         return hr;
   8:  
   9:     BITMAPINFO* pBitmapInfo = (BITMAPINFO*)pDib;
  10:     HDC hScreenDC = ::GetDC(NULL);
  11:     ASSERT(hScreenDC != NULL);
  12:     void* pBits = pDib + sizeof(BITMAPINFOHEADER);
  13:     HBITMAP hBitmap = ::CreateDIBitmap(hScreenDC,&(pBitmapInfo->bmiHeader),CBM_INIT,pBits,pBitmapInfo,DIB_RGB_COLORS);
  14:     //
  15:     //Do something with hBitmap here
  16:     //
  17:     ::DeleteObject(hBitmap);
  18:     ::ReleaseDC(NULL,hScreenDC);
  19:     ::CoTaskMemFree(pDib);
  20:  
  21:     return hr;
  22: }

posted on 2009-07-08 00:22  wudong  阅读(1903)  评论(0编辑  收藏  举报

导航