.NET Framework Class Library for Silverlight
WriteableBitmap Class

Provides a BitmapSource that can be written to and updated.

Namespace:  System.Windows.Media.Imaging
Assembly:  System.Windows (in System.Windows.dll)
Syntax

Visual Basic (Declaration)
Public NotInheritable Class WriteableBitmap _
    Inherits BitmapSource
Visual Basic (Usage)
Dim instance As WriteableBitmap
C#
public sealed class WriteableBitmap : BitmapSource
Remarks

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.

NoteNote:

WriteableBitmap does not render popup controls such as Popup, ComboBox and ToolTip.

Examples

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

XAML
<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>
C#
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);
}
Inheritance Hierarchy

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows.Media..::.ImageSource
      System.Windows.Media.Imaging..::.BitmapSource
        System.Windows.Media.Imaging..::.WriteableBitmap
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Tags :


Community Content

ShaneK2
silverlight helpers @codeplex
http://writeablebitmapex.codeplex.com/

Page view tracker