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->Quer
yInterface
(IID_IVMRM
ixerBitmap
, (void**)(&pPinnedVMRMixerB
itmap9));
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->GetAlpha
BitmapPara
meters(pVM
R9AlphaBit
map);
/// 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->UpdateAl
phaBitmapP
arameters(
pVMR9Alpha
Bitmap);
/// This is the image to be overlayed
Bitmap ^pBitmap = gcnew Bitmap(320, 240, PixelFormat::Format24bppRg
b);
Graphics ^pTestGraphics = Graphics::FromImage(pBitma
p);
pTestGraphics->DrawLine(gc
new Pen(Color::Red), 0, 0, pBitmap->Width, pBitmap->Height);
Color keyColor = Color::White;
/// Here we have some managed GDI - native voodoo
pGraphics = Graphics::FromImage(pBitma
p);
pBitmapHDeviceContext = pGraphics->GetHdc();
hDeviceContext = CreateCompatibleDC((HDC)pB
itmapHDevi
ceContext.
ToPointer(
));
pHBitmap = pBitmap->GetHbitmap();
SelectObject(hDeviceContex
t, (HGDIOBJ)pHBitmap.ToPointe
r());
/// 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_SrcColorKe
y | 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.lef
t = 0;
pVMR9AlphaBitmap->rSrc.bot
tom = (LONG)pBitmap->Height;
pVMR9AlphaBitmap->rSrc.rig
ht = (LONG)pBitmap->Width;
/// Specifies the destination rectangle in composition space.
pVMR9AlphaBitmap->rDest.to
p = 0;
pVMR9AlphaBitmap->rDest.le
ft = 0;
pVMR9AlphaBitmap->rDest.bo
ttom = 1;
pVMR9AlphaBitmap->rDest.ri
ght = 1;
/// Specifies the source color key.
pVMR9AlphaBitmap->clrSrcKe
y = ColorTranslator::ToWin32(k
eyColor);
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->dwFilter
Mode = 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->SetAlpha
Bitmap(pVM
R9AlphaBit
map);
pVMRMixerBitmap9->UpdateAl
phaBitmapP
arameters(
pVMR9Alpha
Bitmap);
}