现在的位置: 首页 > 综合 > 正文

[DirectShow] 抓圖範例

2012年01月09日 ⁄ 综合 ⁄ 共 1634字 ⁄ 字号 评论关闭

原贴地址

http://mqjing.blogspot.com/2007/12/directshow.html

pWC is pointer of CComPtr< IVMRWindowlessControl >

#define BFT_BITMAP 0x4d42   // 'BM'
#define DibNumColors(lpbi)      ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 /
                                    ? (int)(1 << (int)(lpbi)->biBitCount)          /
                                    : (int)(lpbi)->biClrUsed)
#define DibSize(lpbi)           ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
#define DibPaletteSize(lpbi)    (DibNumColors(lpbi) * sizeof(RGBQUAD))

void CEDVRPlayer::OnBnClickedButton2(){
    HRESULT hr;
    TCHAR *szFile=_T("c://test.bmp");

    // 抓圖測試
    BYTE *lpDib = NULL;
    hr = pWC->GetCurrentImage(&lpDib);
    if (SUCCEEDED(hr)){
        BITMAPFILEHEADER    hdr;
        DWORD               dwSize, dwWritten;
        LPBITMAPINFOHEADER  pdib = (LPBITMAPINFOHEADER) lpDib;

        // Create a new file to store the bitmap data
        HANDLE hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

        if (hFile == INVALID_HANDLE_VALUE)
            return ;

        // Initialize the bitmap header
        dwSize = DibSize(pdib);
        hdr.bfType          = BFT_BITMAP;
        hdr.bfSize          = dwSize + sizeof(BITMAPFILEHEADER);
        hdr.bfReserved1     = 0;
        hdr.bfReserved2     = 0;
        hdr.bfOffBits       = (DWORD)sizeof(BITMAPFILEHEADER) + pdib->biSize +
            DibPaletteSize(pdib);

        // Write the bitmap header and bitmap bits to the file
        WriteFile(hFile, (LPCVOID) &hdr, sizeof(BITMAPFILEHEADER), &dwWritten, 0);
        WriteFile(hFile, (LPCVOID) pdib, dwSize, &dwWritten, 0);

        // Close the file
        CloseHandle(hFile);

        CoTaskMemFree(lpDib);
    }
    // end of 抓圖測試

 

抱歉!评论已关闭.