Do not use on any
shared computer
August 29, 2008 08:05pm pdt
 
[x]
Attachment Details

Video overlay / VMRMixerBitmap doesn't show

Tags: overlay, video
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);
}
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: Daeljan
Solution Provided By: Computer101
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Author Comment by Daeljan
Author Comment by Daeljan:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by Venabili
Administrative Comment by Venabili:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Daeljan
Author Comment by Daeljan:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by Venabili
Administrative Comment by Venabili:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Computer101
Accepted Solution by Computer101:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628