Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

Ticker ( Showing or Scrolling Text Over Running Video )

3.33/5 (8 votes)
26 Sep 20061 min read 1   1.8K  
This article tells how you can show your text over video, change text, text color, text background color and its transparency.
Sample Image - Ticker.jpg

Introduction

Showing something over running video? You can see my previous article to show an image over video. But this time, I am going to do some more artwork or text work over running video.

Ticker

Displaying text over video? This project has some similarities with my previous project, but it is not much similar. Here the text also scrolls over video.

Prerequisite

It is a prerequisite to read my article which displays image over video. This is because in that article, I have explained everything which is required to display an image over video, and displaying the text is not much different. So here in this article, I will just stick to the working code which is needed to display text over video.

Prepare the Ground with IVMRMixerControl9

First of all we need to set some preferences for mixing. Because the default mixing preferences are not good for blending the text over video, in the code below I am doing the same:

C++
// Request point filtering (instead of bilinear filtering)
// to improve the text quality. In general, if you are
// not scaling the app Image, you should use point filtering.
// This is very important if you are doing source color keying.
pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMix);
DWORD dwPrefs=0;
pMix->GetMixingPrefs(&dwPrefs);
dwPrefs |= MixerPref_PointFiltering;
dwPrefs &= ~(MixerPref_BiLinearFiltering);
pMix->SetMixingPrefs(dwPrefs);

Preparing the Image From Text

Now we need to make the image having the text we want to show over video.

C++
CDC * pdc = GetDC(); 
CDC mCompatibleDC;
mCompatibleDC.CreateCompatibleDC(pdc);
mCompatibleDC.SelectObject(mFont);
CSize strSize = mCompatibleDC.GetTextExtent(strFinish);
CBitmap bm;
bm.CreateCompatibleBitmap(pdc,strSize.cx,strSize.cy);
mCompatibleDC.SelectObject(&bm);
mCompatibleDC.SetBkColor(mBK_Color);
mCompatibleDC.SetTextColor(mTXT_Color);
mCompatibleDC.TextOut(0,0,strFinish);

Showing the Text Over Video

Now we will prepare for showing the image with text over video.

C++
VMR9AlphaBitmap bmpInfo;
ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
bmpInfo.dwFlags |= VMRBITMAP_HDC;
bmpInfo.hdc = pDC->m_hDC;
LONG cx, cy;
pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL);
bmpInfo.rSrc = Rect;
// rDest specifies the destination rectangle in composition space (0.0f to 1.0f)
bmpInfo.rDest.right = 1.0f;
bmpInfo.rDest.left = 0.0f;
bmpInfo.rDest.top = (float)(cy - Rect.Height()) / (float)cy - EDGE_BUFFER;
bmpInfo.rDest.bottom = 1.0f - EDGE_BUFFER;
// Set the transparency value (1.0 is opaque, 0.0 is transparent).
bmpInfo.fAlpha = 1.0;
pBmp->SetAlphaBitmap(&bmpInfo);

All is done. Now you can blend any text over video.

More Info

If you are interested in more information, see my blog.

History

  • 26 Sep 2006 First version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here