Tuesday, January 22, 2008

Video Brush in 5 minutes or less

The Video brush is a great way to do some cool special effects. To make a video brush work on you have to have a named media element that you can bind to. That has a bound source. In the sample below we have a source. We have set the element to be muted but play and its opacity is 0 so no one sees it on screen. Then we add some text in a text block app and add a foreground element with a ‘video’ brush. The video brush element is bound to the media element by using the media element name. Using a video brush you can basically make just about anything play video.

<MediaElement Name="MediaElementElement" Source="ImenSample.2.wmv" Canvas.Left="20" Canvas.Top="20" Width="100" Height="100" IsMuted="True" AutoPlay="True" Opacity="0" />

<TextBlock Name="Sample Text" FontSize="20" FontFamily="Verdana" FontWeight="Bold" Canvas.Left="10" Canvas.Top="50" Opacity="1" >PAINT WITH VIDEO <TextBlock.Foreground> <VideoBrush SourceName="MediaElementElement" /> </TextBlock.Foreground> </TextBlock>


When this Xaml is rendered we get the text ‘Paint with video’ that is actually playing the video in the background of the text.

2 comments:

  1. Hola! Te cuento que estoy haciendo el mismo cdig en una web para darle video brush a un grid, dilema... se me pone MUY LENTA LA WEB. .. crees qu habra forma de no cargar el video por tras y solo brindarle por codigo el brush al grid? Intenté pero no consegui forma ...

    ReplyDelete