Represents a container for bitmap frames. Each bitmap frame is a BitmapSource. This abstract class provides a base set of functionality for all derived decoder objects.
Namespace:
System.Windows.Media.Imaging
Assembly:
PresentationCore (in PresentationCore.dll)
Visual Basic (Declaration)
Public MustInherit Class BitmapDecoder _
Inherits DispatcherObject
Dim instance As BitmapDecoder
public abstract class BitmapDecoder : DispatcherObject
public ref class BitmapDecoder abstract : public DispatcherObject
public abstract class BitmapDecoder extends DispatcherObject
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.
BitmapDecoder is not a BitmapFrame itself; rather, it is a container for BitmapFrame objects. Each BitmapFrame in the container can potentially have different attributes, including different sizes, resolutions, or palettes.
Unless a specific codec is selected, Windows Presentation Foundation (WPF) uses automatic run-time discovery to identify the format of an image and match it with the appropriate codec. This discovery process allows a codec developed by an independent software vendor (ISV) to be automatically discoverable by the system. To select a specific codec, the derived BitmapDecoder or BitmapEncoder, such as the TiffBitmapDecoder class, should be used.
Tagged Image File Format (TIFF) and Graphics Interchange Format (GIF) are the only implemented image formats that support multiple frames.
The following example demonstrates how to use the Create(Uri, BitmapCreateOptions, BitmapCacheOption) method to create a decoder for a given image. The first BitmapFrame of the image is used as the source of an Image control.
Dim uriBitmap As BitmapDecoder = BitmapDecoder.Create(New Uri("sampleImages/waterlilies.jpg", UriKind.Relative), BitmapCreateOptions.None, BitmapCacheOption.Default)
' Create an image element;
Dim uriImage As New Image()
uriImage.Width = 200
' Set image source.
uriImage.Source = uriBitmap.Frames(0)
BitmapDecoder uriBitmap = BitmapDecoder.Create(
new Uri("sampleImages/waterlilies.jpg", UriKind.Relative),
BitmapCreateOptions.None,
BitmapCacheOption.Default);
// Create an image element;
Image uriImage = new Image();
uriImage.Width = 200;
// Set image source.
uriImage.Source = uriBitmap.Frames[0];
The following code example demonstrates how to use the built in TiffBitmapDecoder to open and decode a Tagged Image File Format (TIFF) bitmap. The resulting BitmapSource is used as the Source of an Image element.
' Open a Stream and decode a TIFF image
Dim imageStreamSource As New FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource As BitmapSource = decoder.Frames(0)
' Draw the Image
Dim myImage1 As New Image()
myImage1.Source = bitmapSource
myImage1.Stretch = Stretch.None
myImage1.Margin = New Thickness(20)
// Open a Stream and decode a TIFF image
Stream imageStreamSource = new FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
// Draw the Image
Image myImage1 = new Image();
myImage1.Source = bitmapSource;
myImage1.Stretch = Stretch.None;
myImage1.Margin = new Thickness(20);
System..::.Object
System.Windows.Threading..::.DispatcherObject
System.Windows.Media.Imaging..::.BitmapDecoder
System.Windows.Media.Imaging..::.BmpBitmapDecoder
System.Windows.Media.Imaging..::.GifBitmapDecoder
System.Windows.Media.Imaging..::.IconBitmapDecoder
System.Windows.Media.Imaging..::.JpegBitmapDecoder
System.Windows.Media.Imaging..::.LateBoundBitmapDecoder
System.Windows.Media.Imaging..::.PngBitmapDecoder
System.Windows.Media.Imaging..::.TiffBitmapDecoder
System.Windows.Media.Imaging..::.WmpBitmapDecoder
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources