BitmapEncoder class

Applies to Windows and Windows Phone

Contains methods to create, edit and save images.

Syntax

Public NotInheritable Class BitmapEncoder

Attributes

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Members

The BitmapEncoder class has these types of members:

Methods

The BitmapEncoder class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
CreateAsync(Guid, IRandomAccessStream) Asynchronously creates a new BitmapEncoder.
CreateAsync(Guid, IRandomAccessStream, IIterable(IKeyValuePair)) Asynchronously creates a new BitmapEncoder for the specified codec with the specified encoding options and initializes it on a stream.
CreateForInPlacePropertyEncodingAsync Asynchronously creates a new BitmapEncoder for in-place property and metadata editing.
CreateForTranscodingAsync Asynchronously creates a new BitmapEncoder and initializes it using data from an existing BitmapDecoder.
FlushAsync Asynchronously commits and flushes all of the image data.
GetEncoderInformationEnumerator A list of the bitmap encoders installed on the system and information about them.
GoToNextFrameAsync() Asynchronously commits the current frame data and appends a new empty frame to be edited.
GoToNextFrameAsync(IIterable(IKeyValuePair)) Asynchronously commits the current frame data and appends a new empty frame, with the specified encoding options, to be edited.
SetPixelData Sets pixel data on the frame.

 

Properties

The BitmapEncoder class has these properties.

PropertyAccess typeDescription

BitmapContainerProperties

Read-onlyThe metadata for the container.

BitmapProperties

Read-onlyThe metadata for the selected frame.

BitmapTransform

Read-onlyA BitmapTransform object that is used to specify how the frame bitmap is to be transformed.

BmpEncoderId

Read-onlyThe unique identifier of the built-in BMP encoder.

EncoderInformation

Read-onlyInformation about the bitmap encoder.

GeneratedThumbnailHeight

Read/writeThe height, in pixels, of any generated thumbnail.

GeneratedThumbnailWidth

Read/writeThe width, in pixels, of any generated thumbnail.

GifEncoderId

Read-onlyThe unique identifier of the built-in GIF encoder.

IsThumbnailGenerated

Read/writeIndicates whether or not a new thumbnail is automatically generated.

JpegEncoderId

Read-onlyThe unique identifier of the built-in JPEG encoder.

JpegXREncoderId

Read-onlyThe unique identifier of the built-in JPEG-XR encoder.

PngEncoderId

Read-onlyThe unique identifier of the built-in PNG encoder.

TiffEncoderId

Read-onlyThe unique identifier of the built-in TIFF encoder.

 

Remarks

Image formats

BitmapEncoder can encode the following formats.

  • JPEG
  • PNG
  • GIF
  • TIFF
  • BMP
  • JPEG-XR

For a list of decoding formats, see the BitmapDecoder topic.

BitmapEncoder behaves differently from BitmapDecoder in that it doesn't provide random access to the frames in an image. Instead, you need to perform actions on the encoder in a specific order.

When you create a BitmapEncoder, it provides access to data on the container and the first frame. When you are done setting data on the first frame and container, if you don't want to encode any additional frames, then call FlushAsync to complete the encoding operation.

If you want to encode an additional frame, call GoToNextFrameAsync. This commits the data in the container and the first frame so you can't edit them anymore. At this point any actions you perform on the encoder will affect the second frame. After you are done with each frame, you can call GoToNextFrameAsync to commit and append a new frame, or call FlushAsync to finish.

Examples

Here's a partial example of creating an encoder object. This example assumes you selected a file with Windows.Storage.Pickers.FileSavePicker. For full instructions on selecting a file, creating an encoder, and encoding an image see How to encode an image


file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (_stream) {
        stream = _stream;

        var encoderId;
        switch (fileType) {
            case ".jpg":
                encoderId = Windows.Graphics.Imaging.BitmapEncoder.jpegEncoderId;
                break;
        }
        return Windows.Graphics.Imaging.BitmapEncoder.createAsync(encoderId, stream);
        }).then(function (encoder) {

														// Your code here.
	       }


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Graphics.Imaging
Windows::Graphics::Imaging [C++]

Metadata

Windows.winmd

See also

How to encode an image

 

 

Show:
© 2014 Microsoft