Namespace:
System.Windows.Media.Imaging
Assembly:
System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public NotInheritable Class WriteableBitmap _
Inherits BitmapSource
Dim instance As WriteableBitmap
public sealed class WriteableBitmap : BitmapSource
Use the WriteableBitmap class to update and render a bitmap on a per-frame basis. This is useful for taking snapshots of playing video, generating algorithmic content, such as a fractal image, and for data visualization, such as a music visualizing application.
You can use this class's constructor to render a bitmap or, if you want to render the bitmap multiple times, use the Render method. If you use the Render method, you will need to call Invalidate in order for the bitmap to render.
When assigning colors to pixels in your bitmap, use pre-multiplied colors.
The following example demonstrates how to use a WriteableBitmap to take snapshots of a playing video and display those snapshots as thumbnails. Click on the video as it plays to create the thumbnails.
Run this sample
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="10">
<Border BorderBrush="AntiqueWhite" BorderThickness="2" CornerRadius="1" Margin="4"
HorizontalAlignment="Center" VerticalAlignment="Top">
<Border>
<MediaElement x:Name="myMediaElement" Source="xbox.wmv" Stretch="None" MouseLeftButtonDown="me_MouseLeftButtonDown"/>
</Border>
</Border>
<!-- thumbnails go here -->
<StackPanel x:Name="thumbs" Orientation="Horizontal" Margin="10,40,10,10">
</StackPanel>
</StackPanel>
private void me_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Create a WriteableBitmap and set it to the MediaElement (video).
// The WriteableBitmap represents a "snapshot" of the video.
WriteableBitmap wb = new WriteableBitmap(myMediaElement, null);
// Create an image of the desired size and set its source to
// the WriteableBitmap representing a snapshot of the video.
Image image = new Image();
image.Height = 64;
image.Margin = new Thickness(10);
image.Source = wb;
// Display the snapshot of the video among the thumbnails.
thumbs.Children.Add(image);
}
System..::.Object
System.Windows..::.DependencyObject
System.Windows.Media..::.ImageSource
System.Windows.Media.Imaging..::.BitmapSource
System.Windows.Media.Imaging..::.WriteableBitmap
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Reference