Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
4.00/5 (1 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:
C++
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,
                                    MAKEINTRESOURCE(IDB_BITMAP1));
  	BITMAP bm;
        GetObject(hBitmap, sizeof(bm), &bm);
        int mBitmapWidth = bm.bmWidth;
	int mBitmapHeight= bm.bmHeight;
	mCompatibleDC.CreateCompatibleDC(pdc);
	mCompatibleDC.SelectObject(hBitmap);
	CRect reSrc(0,0,mBitmapWidth,mBitmapHeight);
	CRect reDst;
	//mVideoClass.ShowImage(&mCompatibleDC,reSrc);
	alphaBitmap.dwFlags |= VMR9AlphaBitmap_hDC;
	alphaBitmap.hdc = mCompatibleDC.m_hDC;
	alphaBitmap.rSrc = reSrc;
	CRect mRect;
	mRect.SetRect(0,0,45,75);
        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;
	alphaBitmap.rDest.top = 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);
	pMixerBmp->SetAlphaBitmap(&alphaBitmap);	
}

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,
J.SurjithKumar
Posted
Updated 28-Feb-13 2:37am
v14
Comments
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:

http://msdn.microsoft.com/en-gb/library/windows/desktop/dd390457(v=vs.85).aspx

I think you may need to get a different interface
J.Surjith Kumar 25-Feb-13 4:46am    
That is IVMRMixerBitmap9 interface.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd390451(v=vs.85).aspx
Chris Reynolds (UK) 25-Feb-13 4:53am    
Yes, you're asking for the Control interface:
pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMixerBmp);

1 solution

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
 
Share this answer
 
Comments
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:

http://www.codeproject.com/Articles/224754/Guide-to-Win32-Memory-DC
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!?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900