Ok, I'm going to include a code snippet (with all error handling and cleanup removed) to help with this one. I'm using the VMR to render the video stream, and I want to overlay a bitmap image. As I understand, the Mixer bitmap serves this purpose. The video displays, but the overlay doesn't, and I cant see why - I have scratched my head for a while over this one, and searched the internet too - it seems to me that it should work (I'm using managed extensions to C++ btw). I'd be grateful if someone could point out the error of my ways...
This is how I obtain the mixer bitmap:
pin_ptr<IVMRMixerBitmap9*> pPinnedVMRMixerBitmap9 = &pVMRMixerBitmap9;
hResult = pVideoMixingRenderer->QueryInterface(IID_IVMRMixerBitmap, (void**)(&pPinnedVMRMixerBitmap9));
pVMRMixerBitmap9 = (IVMRMixerBitmap9 *)pPinnedVMRMixerBitmap9;
InitialiseVMRMixerBitmap();
And this is the InitialiseVMRMixerBitmap() body:
void InitialiseVMRMixerBitmap()
{
HRESULT hResult = NOERROR;
Graphics ^pGraphics = nullptr;
IntPtr pBitmapHDeviceContext = IntPtr::Zero;
IntPtr pHBitmap = IntPtr::Zero;
HDC hDeviceContext = (HDC)0;
pVMR9AlphaBitmap = new VMR9AlphaBitmap();
/// Get current Alpha Bitmap parameters
hResult = pVMRMixerBitmap9->GetAlphaBitmapParameters(pVMR9AlphaBitmap);
/// Put this into a know condition
memset(pVMR9AlphaBitmap, 0, sizeof(VMR9AlphaBitmap));
/// Disable the them by setting this enumeration and writing them back to the mixer
pVMR9AlphaBitmap->dwFlags = VMR9AlphaBitmap_Disable;
hResult = pVMRMixerBitmap9->UpdateAlphaBitmapParameters(pVMR9AlphaBitmap);
/// This is the image to be overlayed
Bitmap ^pBitmap = gcnew Bitmap(320, 240, PixelFormat::Format24bppRgb);
Graphics ^pTestGraphics = Graphics::FromImage(pBitmap);
pTestGraphics->DrawLine(gcnew Pen(Color::Red), 0, 0, pBitmap->Width, pBitmap->Height);
Color keyColor = Color::White;
/// Here we have some managed GDI - native voodoo
pGraphics = Graphics::FromImage(pBitmap);
pBitmapHDeviceContext = pGraphics->GetHdc();
hDeviceContext = CreateCompatibleDC((HDC)pBitmapHDeviceContext.ToPointer());
pHBitmap = pBitmap->GetHbitmap();
SelectObject(hDeviceContext, (HGDIOBJ)pHBitmap.ToPointer());
/// Now we can configure the alpha bitmap to use the GDI device context
pVMR9AlphaBitmap = new VMR9AlphaBitmap();
/// Bitwise combination of flags from the VMR9AlphaBitmapFlags enumeration type.
pVMR9AlphaBitmap->dwFlags = VMR9AlphaBitmap_hDC | VMR9AlphaBitmap_SrcColorKey | VMR9AlphaBitmap_FilterMode;
/// Specifies the handle to the device context for the bitmap. Specify NULL if the bitmap is located in a Direct3D surface.
pVMR9AlphaBitmap->hdc = hDeviceContext;
/// Specifies the source rectangle in either the GDI device context or the DirectDraw surface.
pVMR9AlphaBitmap->rSrc.top = 0;
pVMR9AlphaBitmap->rSrc.left = 0;
pVMR9AlphaBitmap->rSrc.bottom = (LONG)pBitmap->Height;
pVMR9AlphaBitmap->rSrc.right = (LONG)pBitmap->Width;
/// Specifies the destination rectangle in composition space.
pVMR9AlphaBitmap->rDest.top = 0;
pVMR9AlphaBitmap->rDest.left = 0;
pVMR9AlphaBitmap->rDest.bottom = 1;
pVMR9AlphaBitmap->rDest.right = 1;
/// Specifies the source color key.
pVMR9AlphaBitmap->clrSrcKey = ColorTranslator::ToWin32(keyColor);
pVMR9AlphaBitmap->pDDS = NULL;
/// Specifies flags from the VMRMixerPrefs enumeration, which control how the VMR mixes the image.
/// The MixerPref_PointFiltering flag is particularly useful for images that contain text and do
/// not need to be stretched prior to mixing.
pVMR9AlphaBitmap->dwFilterMode = MixerPref_PointFiltering;
/// Specifies the alpha blending value; must be a value from 0.0 to 1.0 (inclusive).
pVMR9AlphaBitmap->fAlpha = 1.0;
/// To remove the bitmap, set the VMR9AlphaBitmap_Disable flag in the VMR9AlphaBitmap structure
/// and call SetAlphaBitmap again.
hResult = pVMRMixerBitmap9->SetAlphaBitmap(pVMR9AlphaBitmap);
pVMRMixerBitmap9->UpdateAlphaBitmapParameters(pVMR9AlphaBitmap);
}
by: DaeljanPosted on 2007-08-30 at 04:40:50ID: 19799067
bump!
(does that even work here?)
:)