Click here to Skip to main content
11,705,212 members (47,692 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C MFC directshow VC++
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,
                                    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 21-Feb-13 23:17pm
Edited 28-Feb-13 2:37am
v14
Comments
Chris Reynolds (UK) at 22-Feb-13 9:43am
   
Any idea which line is throwing the exception?
J.Surjith Kumar at 25-Feb-13 0:09am
   
pMixerBmp->SetAlphaBitmap(&alphaBitmap);//Exception throws here
Chris Reynolds (UK) at 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 at 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) at 25-Feb-13 4:53am
   
Yes, you're asking for the Control interface:
pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMixerBmp);
J.Surjith Kumar at 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
good
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. Blush | :O
  Permalink  
Comments
J.Surjith Kumar at 26-Feb-13 8:07am
   
Can you give me any reference regarding your solution.
KarstenK at 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 at 26-Feb-13 8:28am
   
Its all about bitmaps. How to play the video in a memory dc!?
KarstenK at 26-Feb-13 8:53am
   
playing a video is showing pictures with a frame rate.
J.Surjith Kumar at 26-Feb-13 8:57am
   
How to achieve that by using directshow!?
J.Surjith Kumar at 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
0 Sergey Alexandrovich Kryukov 550
1 OriginalGriff 244
2 ppolymorphe 126
3 CPallini 82
4 F-ES Sitecore 70
0 OriginalGriff 8,988
1 Sergey Alexandrovich Kryukov 8,272
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2015
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