Microsoft DirectX 8.1 (C++)

IMediaDet::GetBitmapBits

The GetBitmapBits method retrieves a poster frame at the specified media time.

Syntax

HRESULT GetBitmapBits(
    double StreamTime, 
    long *pBufferSize, 
    char *pBuffer, 
    long Width, 
    long Height
);

Parameters

StreamTime

Time at which to retrieve the poster frame.

pBufferSize

Pointer to a variable that receives the required buffer size. If pBuffer is NULL, the variable receives the size of the buffer needed to retrieve the poster frame. If pBuffer is not NULL, this parameter is ignored.

pBuffer

Pointer to a buffer that receives a BITMAPINFOHEADER structure followed by the DIB bits.

Width

Width of the poster frame image, in pixels.

Height

Height of the poster frame image, in pixels.

Return Value

Returns an HRESULT value. Possible values include the following:

Value Description
S_OK Success.
E_NOINTERFACE Could not add the Sample Grabber filter to the graph.
E_OUTOFMEMORY Insufficient memory.
E_POINTER NULL pointer error.
E_UNEXPECTED Unexpected error.
VFW_E_INVALIDMEDIATYPE Invalid media type.

Remarks

Before calling this method, set the file name and stream by calling IMediaDet::put_Filename and IMediaDet::put_CurrentStream.

To determine the size of the buffer that is required, call this method with pBuffer equal to NULL. The size is returned in the variable pointed to by pBufferSize. Then create the buffer and call the method again, with pBuffer equal to the address of the buffer. When the method returns, the buffer contains a BITMAPINFOHEADER structure followed by the bitmap. The bitmap is scaled to the dimensions specified in the Width and Height parameters.

This method puts the media detector into bitmap grab mode. Once this method has been called, the various stream information methods in IMediaDet do not work, unless you create a new instance of the media detector.

Example Code

The following code uses the GetBitmapBits method to create a device-independent bitmap.

long size;
hr = pDet->GetBitmapBits(0, &size, 0, width, height);
if (SUCCEEDED(hr)) 
{
    char *pBuffer = new char[size];
    if (!pBuffer)
        return E_OUTOFMEMORY;
    try {
        hr = pDet->GetBitmapBits(0, 0, pBuffer, width, height);
    }
    catch (...) {
        delete [] pBuffer;
        return E_FAIL;
    }
    if (SUCCEEDED(hr))
    {
        BITMAPINFOHEADER *bmih = (BITMAPINFOHEADER*)pBuffer;
        HDC hdcDest = GetDC(0);
        void *pData = pBuffer + sizeof(BITMAPINFOHEADER);
        
        BITMAPINFO bmi;
        ZeroMemory(&bmi, sizeof(BITMAPINFO));
        CopyMemory(&(bmi.bmiHeader), bmih, sizeof(BITMAPINFOHEADER));
        HBITMAP hBitmap = CreateDIBitmap(hdcDest, bmih, CBM_INIT, 
            pData, &bmi, DIB_RGB_COLORS);
    }
    delete[] pBuffer;
}

See Also