Microsoft DirectX 9.0

Mixing an Image Onto the Video Window in Visual Basic

This topic applies to Windows XP only.

This section describes how to display an alpha-blended image over the Video Control's video image. Internally, the Video Control uses the Video Mixing Renderer filter (VMR). After you call the View method on the Video Control to build the filter graph, the MSVidCtl.VideoRendererActive property holds a reference to an MSVidVideoRenderer device object, which controls the VMR.

First obtain an IPictureDisp object to use as the image. For example, you can load an image file, or capture a frame from the Video Control:

Dim iPic As IPictureDisp
' Load an image.
Set iPic = LoadPicture("MyPicture.gif")
' ... or capture a frame.
Set iPic = VideoControl.VideoRendererActive.Capture

Set the MSVidVideoRenderer.MixerBitmapPositionRect property to specify the position of the image as it will appear on the Video Control window. The default position is the entire window. The following example places the image in the upper-left corner of the window:

ScaleMode = 3 ' pixels
Dim iVid As MSVidVideoRenderer
Set iVid = gTV.VideoRendererActive
iVid.MixerBitmapPositionRect.Top = 0
iVid.MixerBitmapPositionRect.Left = 0
iVid.MixerBitmapPositionRect.Height = VideoControl.Height / 2
iVid.MixerBitmapPositionRect.Width = VideoControl.Width / 2
iVid.MixerBitmapPositionRect = rect

The MixerBitmapPositionRect property is an IMSVidRect object, which represents a rectangle. This example modifies the rectangle's coordinates in place. Note that if you set a reference to the MixerBitmapPositionRect property, the property returns a copy of the original rectangle. Modifying the copy does not change the original rectangle. For example:

Dim rect As IMSVidRect
Set rect = VideoControl.VideoRendererActive.MixerBitmapPositionRect
' This is a copy of the rectangle!
rect.Height = VideoControl.Height / 2
rect.Width = VideoControl.Width / 2
' To modify the original, put the copy back into the property: 
VideoControl.VideoRendererActive.MixerBitmapPositionRect = rect

The rectangle coordinates are in pixels, not twips, so call the ScaleMode function before retrieving the Video Control's Height and Width properties.

Finally, specify the desired opacity and the image by setting the MSVidVideoRenderer.MixerBitmapOpacity and MSVidVideoRenderer.MixerBitmap properties:

iVid.MixerBitmapOpacity = 80
iVid.MixerBitmap = iPic

Opacity is expressed as a percentage from 0 to 100. You can set all three properties at once using the MSVidVideoRenderer.SetupMixerBitmap method:

VideoControl.VideoRendererActive.SetupMixerBitmap iPic, 80, rect