BitmapEncoder Class

Definition

Contains methods to create, edit and save images.

public ref class BitmapEncoder sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.Graphics.Imaging.IBitmapEncoderStatics, 65536, Windows.Foundation.UniversalApiContract)]
class BitmapEncoder sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.Graphics.Imaging.IBitmapEncoderStatics, 65536, "Windows.Foundation.UniversalApiContract")]
class BitmapEncoder sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.Graphics.Imaging.IBitmapEncoderStatics, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.Graphics.Imaging.IBitmapEncoderStatics2, 458752, "Windows.Foundation.UniversalApiContract")]
class BitmapEncoder sealed
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.Graphics.Imaging.IBitmapEncoderStatics), 65536, typeof(Windows.Foundation.UniversalApiContract))]
public sealed class BitmapEncoder
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.Graphics.Imaging.IBitmapEncoderStatics), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class BitmapEncoder
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.Graphics.Imaging.IBitmapEncoderStatics), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.Graphics.Imaging.IBitmapEncoderStatics2), 458752, "Windows.Foundation.UniversalApiContract")]
public sealed class BitmapEncoder
Public NotInheritable Class BitmapEncoder
Inheritance
BitmapEncoder
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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 Imaging

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.
        }

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.Bitmap encoders may expose various encoding options that affect the quality, size and other properties of the encoded output file. For more info, see Imaging.

Version history

Windows version SDK version Value added
1809 17763 HeifEncoderId

Properties

BitmapContainerProperties

The metadata for the container.

BitmapProperties

The metadata for the selected frame.

BitmapTransform

A BitmapTransform object that is used to specify how the frame bitmap is to be transformed.

BmpEncoderId

The unique identifier of the built-in BMP encoder.

EncoderInformation

Information about the bitmap encoder.

GeneratedThumbnailHeight

The height, in pixels, of any generated thumbnail.

GeneratedThumbnailWidth

The width, in pixels, of any generated thumbnail.

GifEncoderId

The unique identifier of the built-in GIF encoder.

HeifEncoderId

The unique identifier of the built-in HEIF encoder.

IsThumbnailGenerated

Indicates whether or not a new thumbnail is automatically generated.

JpegEncoderId

The unique identifier of the built-in JPEG encoder.

JpegXREncoderId

The unique identifier of the built-in JPEG-XR encoder.

PngEncoderId

The unique identifier of the built-in PNG encoder.

TiffEncoderId

The unique identifier of the built-in TIFF encoder.

Methods

CreateAsync(Guid, IRandomAccessStream)

Asynchronously creates a new BitmapEncoder.

CreateAsync(Guid, IRandomAccessStream, IEnumerable<KeyValuePair<String,BitmapTypedValue>>)

Asynchronously creates a new BitmapEncoder for the specified codec with the specified encoding options and initializes it on a stream.

CreateForInPlacePropertyEncodingAsync(BitmapDecoder)

Asynchronously creates a new BitmapEncoder for in-place property and metadata editing. The new encoder can only edit bitmap properties in-place and will fail for any other uses.

CreateForTranscodingAsync(IRandomAccessStream, BitmapDecoder)

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(IEnumerable<KeyValuePair<String,BitmapTypedValue>>)

Asynchronously commits the current frame data and appends a new empty frame, with the specified encoding options, to be edited.

SetPixelData(BitmapPixelFormat, BitmapAlphaMode, UInt32, UInt32, Double, Double, Byte[])

Sets pixel data on the frame.

SetSoftwareBitmap(SoftwareBitmap)

Sets the image data of the current frame using the specified SoftwareBitmap.

Applies to

See also