Export (0) Print
Expand All

BmpBitmapDecoder Class

Defines a decoder for bitmap (BMP) encoded images. 

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

public sealed class BmpBitmapDecoder : BitmapDecoder

The BmpBitmapDecoder type exposes the following members.

  NameDescription
Public methodBmpBitmapDecoder(Stream, BitmapCreateOptions, BitmapCacheOption)Initializes a new instance of BmpBitmapDecoder from the specified file stream with the specified createOptions and cacheOption.
Public methodBmpBitmapDecoder(Uri, BitmapCreateOptions, BitmapCacheOption)Initializes a new instance of BmpBitmapDecoder from the specified Uri with the specified createOptions and cacheOption.
Top

  NameDescription
Public propertyCodecInfoGets information that describes this codec. (Inherited from BitmapDecoder.)
Public propertyColorContextsGets a value that represents the color profile associated with a bitmap, if one is defined. (Inherited from BitmapDecoder.)
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public propertyFramesGets the content of an individual frame within a bitmap. (Inherited from BitmapDecoder.)
Public propertyIsDownloadingGets a value that indicates if the decoder is currently downloading content. (Inherited from BitmapDecoder.)
Public propertyMetadataGets an instance of BitmapMetadata that represents the global metadata associated with this bitmap, if metadata is defined. (Inherited from BitmapDecoder.)
Public propertyPaletteGets the BitmapPalette associated with this decoder. (Inherited from BitmapDecoder.)
Public propertyPreviewGets a BitmapSource that represents the global preview of this bitmap, if one is defined. (Inherited from BitmapDecoder.)
Public propertyThumbnailGets a BitmapSource that represents the thumbnail of the bitmap, if one is defined. (Inherited from BitmapDecoder.)
Top

  NameDescription
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public methodCreateInPlaceBitmapMetadataWriterCreates an instance of InPlaceBitmapMetadataWriter, which can be used to update the metadata of a bitmap. (Inherited from BitmapDecoder.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringConverts the current value of a BitmapDecoder to a String. (Inherited from BitmapDecoder.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top

  NameDescription
Public eventDownloadCompletedOccurs when a BitmapDecoder has finished downloading bitmap content. (Inherited from BitmapDecoder.)
Public eventDownloadFailedOccurs when bitmap content failed to download. (Inherited from BitmapDecoder.)
Public eventDownloadProgressOccurs when a BitmapDecoder has made progress downloading bitmap content. (Inherited from BitmapDecoder.)
Top

The following examples show how to decode and encode a bitmap (BMP) image using the specific BmpBitmapDecoder and BmpBitmapEncoder objects.

This example demonstrates how to decode a BMP image using a BmpBitmapDecoder from a Uri.


// Open a Uri and decode a BMP image
Uri myUri = new Uri("tulipfarm.bmp", UriKind.RelativeOrAbsolute);
BmpBitmapDecoder decoder2 = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];

// Draw the Image
Image myImage2 = new Image();
myImage2.Source = bitmapSource2;
myImage2.Stretch = Stretch.None;
myImage2.Margin = new Thickness(20);

This example demonstrates how to encode a BitmapSource into a BMP image using a BmpBitmapEncoder.

            int width = 128;
            int height = width;
            int stride = width / 8;
            byte[] pixels = new byte[height * stride];

            // Try creating a new image with a custom palette.
            List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
            colors.Add(System.Windows.Media.Colors.Red);
            colors.Add(System.Windows.Media.Colors.Blue);
            colors.Add(System.Windows.Media.Colors.Green);
            BitmapPalette myPalette = new BitmapPalette(colors);

            // Creates a new empty image with the pre-defined palette
            BitmapSource image = BitmapSource.Create(
                width,
                height,
                96,
                96,
                PixelFormats.Indexed1,
                myPalette,
                pixels,
                stride);

            FileStream stream = new FileStream("new.bmp", FileMode.Create);
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            TextBlock myTextBlock = new TextBlock();
            myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft