在播放视频上显示图像时出现问题。 [英] Problem in displaying the image over the playing video.

查看:117
本文介绍了在播放视频上显示图像时出现问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VC ++中使用directshow创建视频播放器。我使用一些常用控件成功创建了视频播放器。现在我试图在播放视频上显示图像。这是代码:

  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);
// 此值用于在合成空间中重新定位位图。
float fBmpCompWidth =( float 45 / ( float )cx;
// rDest指定合成空间中的目标矩形(0.0f到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;
// 设置透明度值(1.0是不透明的,0.0是透明的)。
alphaBitmap.fAlpha = 0 0 ;
// 设置COLORREF以使位图轮廓透明
alphaBitmap .dwFlags | = VMR9AlphaBitmap_SrcColorKey;
alphaBitmap.clrSrcKey = RGB( 0 255 0 );
pMixerBmp-> SetAlphaBitmap(& alphaBitmap);
}



它的构建成功,但我将屏幕截图作为图像而不是获取加载的位图。





任何人都可以帮我解决这个错误。



谢谢&此致,

J.SurjithKumar

解决方案

您的源位图没有正确的alpha值或不透明的背景。



如果你创建2个控件会发生什么:一个视频另一个只有bmp。 (用不同的背景准备它们)



一个解决方案是在内存直流中播放视频,而不是在其上比特位图,而不是在屏幕上输出。这会在屏幕上切出一个绘图周期,因此应该表现非常好。 :-O

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

解决方案

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


这篇关于在播放视频上显示图像时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆