Click here to Skip to main content
12,696,493 members (30,420 online)
Rate this:
Please Sign up or sign in to vote.
Am creating the video player using directshow in VC++. I created the video player successfully with some of the common controls. Now am trying to display the image over the playing video. Here is the Code:
void CVMR9Dlg::OnBnClickedDrawimage()
        pVmr->QueryInterface(IID_IVMRMixerBitmap9, (void**)&pMixerBmp);
	ZeroMemory(&alphaBitmap, sizeof(alphaBitmap) );
	const float EDGE_BUFFER  = 0.04f;
	CDC * pdc = GetDC();
	CDC mCompatibleDC;
	HBITMAP hBitmap =LoadBitmap(AfxGetApp()>m_hInstance,
  	BITMAP bm;
        GetObject(hBitmap, sizeof(bm), &bm);
        int mBitmapWidth = bm.bmWidth;
	int mBitmapHeight= bm.bmHeight;
	CRect reSrc(0,0,mBitmapWidth,mBitmapHeight);
	CRect reDst;
	alphaBitmap.dwFlags |= VMR9AlphaBitmap_hDC;
	alphaBitmap.hdc = mCompatibleDC.m_hDC;
	alphaBitmap.rSrc = reSrc;
	CRect mRect;
        LONG cx, cy;
        pWc->GetNativeVideoSize(&cx, &cy, NULL, NULL);
	// This value is used to reposition the bitmap in composition space.
	float fBmpCompWidth = (float)45 / (float)cx;
       //rDest specifies the destination rectangle in composition space (0.0f to 1.0f)
        alphaBitmap.rDest.right  = 1.0f - EDGE_BUFFER;
	alphaBitmap.rDest.left   = 1.0f - fBmpCompWidth- EDGE_BUFFER;
	float mTop = (float)(cy - 75) / (float)cy - EDGE_BUFFER; = mTop;
	float mBottom = 1.0f - EDGE_BUFFER;
	alphaBitmap.rDest.bottom = mBottom; 
	pRect = alphaBitmap.rDest;
	// Set the transparency value (1.0 is opaque, 0.0 is transparent).
        alphaBitmap.fAlpha = 0.0;
	// Set the COLORREF so that the bitmap outline will be transparent
	alphaBitmap.dwFlags |= VMR9AlphaBitmap_SrcColorKey; 
        alphaBitmap.clrSrcKey = RGB(0, 255, 0);

Its build successfully but am getting the screen shot as an image rather than getting the loaded bitmap.

Anyone help me to resolve from this error.

Thanks & Regards,
Posted 22-Feb-13 0:17am
Updated 28-Feb-13 3:37am
Chris Reynolds (UK) 22-Feb-13 9:43am
Any idea which line is throwing the exception?
J.Surjith Kumar 25-Feb-13 0:09am
pMixerBmp->SetAlphaBitmap(&alphaBitmap);//Exception throws here
Chris Reynolds (UK) 25-Feb-13 4:11am
Well I think it might be because that interface (IVMRMixerControl9) doesn't support a methiod called SetAlphaBitmap:

I think you may need to get a different interface
J.Surjith Kumar 25-Feb-13 4:46am
That is IVMRMixerBitmap9 interface.
Chris Reynolds (UK) 25-Feb-13 4:53am
Yes, you're asking for the Control interface:
pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMixerBmp);
J.Surjith Kumar 26-Feb-13 0:39am
Ya got it, I did a mistake now i changed it but rather than display the image which was loaded, it displays the screen shot. Dont know how it came.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your source bitmap hasnt the right alpha value or a nontransparent background.

What happens if you create 2 controls: one the video the other only with the bmp. (Prepare them with a different background)

A solution is to play the video in a memory dc and than bitblt the bitmap over it and than do the output on the screen. This cuts out one drawing cycle on the screen and so should perform very good. :-O
J.Surjith Kumar 26-Feb-13 8:07am
Can you give me any reference regarding your solution.
KarstenK 26-Feb-13 8:24am
I hope reading this will help you to do your work:
J.Surjith Kumar 26-Feb-13 8:28am
Its all about bitmaps. How to play the video in a memory dc!?
KarstenK 26-Feb-13 8:53am
playing a video is showing pictures with a frame rate.
J.Surjith Kumar 26-Feb-13 8:57am
How to achieve that by using directshow!?
J.Surjith Kumar 26-Feb-13 9:11am
using directshow?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100