BitmapEncoder BitmapEncoder BitmapEncoder BitmapEncoder BitmapEncoder Class

Definition

Contains methods to create, edit and save images.

public : sealed class BitmapEncoder : IBitmapEncoder, IBitmapEncoderWithSoftwareBitmap
struct winrt::Windows::Graphics::Imaging::BitmapEncoder : IBitmapEncoder, IBitmapEncoderWithSoftwareBitmap
public sealed class BitmapEncoder : IBitmapEncoder, IBitmapEncoderWithSoftwareBitmap
Public NotInheritable Class BitmapEncoder Implements IBitmapEncoder, IBitmapEncoderWithSoftwareBitmap
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.

Properties

BitmapContainerProperties BitmapContainerProperties BitmapContainerProperties BitmapContainerProperties BitmapContainerProperties

The metadata for the container.

BitmapProperties BitmapProperties BitmapProperties BitmapProperties BitmapProperties

The metadata for the selected frame.

BitmapTransform BitmapTransform BitmapTransform BitmapTransform BitmapTransform

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

BmpEncoderId BmpEncoderId BmpEncoderId BmpEncoderId BmpEncoderId

The unique identifier of the built-in BMP encoder.

EncoderInformation EncoderInformation EncoderInformation EncoderInformation EncoderInformation

Information about the bitmap encoder.

GeneratedThumbnailHeight GeneratedThumbnailHeight GeneratedThumbnailHeight GeneratedThumbnailHeight GeneratedThumbnailHeight

The height, in pixels, of any generated thumbnail.

GeneratedThumbnailWidth GeneratedThumbnailWidth GeneratedThumbnailWidth GeneratedThumbnailWidth GeneratedThumbnailWidth

The width, in pixels, of any generated thumbnail.

GifEncoderId GifEncoderId GifEncoderId GifEncoderId GifEncoderId

The unique identifier of the built-in GIF encoder.

IsThumbnailGenerated IsThumbnailGenerated IsThumbnailGenerated IsThumbnailGenerated IsThumbnailGenerated

Indicates whether or not a new thumbnail is automatically generated.

JpegEncoderId JpegEncoderId JpegEncoderId JpegEncoderId JpegEncoderId

The unique identifier of the built-in JPEG encoder.

JpegXREncoderId JpegXREncoderId JpegXREncoderId JpegXREncoderId JpegXREncoderId

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

PngEncoderId PngEncoderId PngEncoderId PngEncoderId PngEncoderId

The unique identifier of the built-in PNG encoder.

TiffEncoderId TiffEncoderId TiffEncoderId TiffEncoderId TiffEncoderId

The unique identifier of the built-in TIFF encoder.

Methods

CreateAsync(Guid, IRandomAccessStream) CreateAsync(Guid, IRandomAccessStream) CreateAsync(Guid, IRandomAccessStream) CreateAsync(Guid, IRandomAccessStream) CreateAsync(Guid, IRandomAccessStream)

Asynchronously creates a new BitmapEncoder.

CreateAsync(Guid, IRandomAccessStream, IIterable<IKeyValuePair<String, BitmapTypedValue>>) CreateAsync(Guid, IRandomAccessStream, IIterable<IKeyValuePair<String, BitmapTypedValue>>) CreateAsync(Guid, IRandomAccessStream, IIterable<IKeyValuePair<String, BitmapTypedValue>>) CreateAsync(Guid, IRandomAccessStream, IIterable<IKeyValuePair<String, BitmapTypedValue>>) CreateAsync(Guid, IRandomAccessStream, IIterable<IKeyValuePair<String, BitmapTypedValue>>)

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

CreateForInPlacePropertyEncodingAsync(BitmapDecoder) CreateForInPlacePropertyEncodingAsync(BitmapDecoder) CreateForInPlacePropertyEncodingAsync(BitmapDecoder) CreateForInPlacePropertyEncodingAsync(BitmapDecoder) 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) CreateForTranscodingAsync(IRandomAccessStream, BitmapDecoder) CreateForTranscodingAsync(IRandomAccessStream, BitmapDecoder) CreateForTranscodingAsync(IRandomAccessStream, BitmapDecoder) CreateForTranscodingAsync(IRandomAccessStream, BitmapDecoder)

Asynchronously creates a new BitmapEncoder and initializes it using data from an existing BitmapDecoder.

FlushAsync() FlushAsync() FlushAsync() FlushAsync() FlushAsync()

Asynchronously commits and flushes all of the image data.

GetEncoderInformationEnumerator() GetEncoderInformationEnumerator() GetEncoderInformationEnumerator() GetEncoderInformationEnumerator() GetEncoderInformationEnumerator()

A list of the bitmap encoders installed on the system and information about them.

GoToNextFrameAsync() GoToNextFrameAsync() GoToNextFrameAsync() GoToNextFrameAsync() GoToNextFrameAsync()

Asynchronously commits the current frame data and appends a new empty frame to be edited.

GoToNextFrameAsync(IIterable<IKeyValuePair<String, BitmapTypedValue>>) GoToNextFrameAsync(IIterable<IKeyValuePair<String, BitmapTypedValue>>) GoToNextFrameAsync(IIterable<IKeyValuePair<String, BitmapTypedValue>>) GoToNextFrameAsync(IIterable<IKeyValuePair<String, BitmapTypedValue>>) GoToNextFrameAsync(IIterable<IKeyValuePair<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[]) SetPixelData(BitmapPixelFormat, BitmapAlphaMode, UInt32, UInt32, Double, Double, Byte[]) SetPixelData(BitmapPixelFormat, BitmapAlphaMode, UInt32, UInt32, Double, Double, Byte[]) SetPixelData(BitmapPixelFormat, BitmapAlphaMode, UInt32, UInt32, Double, Double, Byte[]) SetPixelData(BitmapPixelFormat, BitmapAlphaMode, UInt32, UInt32, Double, Double, Byte[])

Sets pixel data on the frame.

SetSoftwareBitmap(SoftwareBitmap) SetSoftwareBitmap(SoftwareBitmap) SetSoftwareBitmap(SoftwareBitmap) SetSoftwareBitmap(SoftwareBitmap) SetSoftwareBitmap(SoftwareBitmap)

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

See Also