Video Brush in WPF

Video Brush

A video brush is a brush similar to any other brush. Instead of painting an area with a color, a video brush paints an area with a video. The video contents are provided by a MediaElement. We can use a visualBrush to play a media by setting a MediaElement as its Visual attribute.

The following code snippet creates a MediaElement. The Source property of the MediaElement is the name of the video file.

  <MediaElement Source="Lake.wmv"                              Name="McMediaElement" Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Fill />

The code snippet in Listing 27 creates a VisualBrush and sets its Visual attribute to a MediaElement.

<VisualBrush >
      <VisualBrush.Visual >
<MediaElement Source="Lake.wmv"                              Name="McMediaElement" Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Fill />
      </VisualBrush.Visual >
</VisualBrush >

Listing 27

The code snippet in Listing 28 creates a MediaElement and sets it as the Visual property of a VisualBrush.

MediaElement McMediaElement = new MediaElement();
McMediaElement.Source = new Uri("Lake.wmv", UriKind.Relative);
McMediaElement.IsMuted = false;
 
VisualBrush videoBrush = new VisualBrush ();
videoBrush.Visual = McMediaElement; 

Listing 28


Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.