ImageDecoder Class
Decodes the frames of an encoded image (https://w3c.github.io/webcodecs/#imagedecoder) with the image decoders of the rendering backend (BrowsingContextOptions.RenderingBackend), the ones of the img elements: PNG (including the animated PNG), JPEG, GIF, WebP, AVIF, JPEG XL, BMP and ICO with the backend of Meziantou.Framework.WebPlatform.Imaging. The data is a buffer, or a stream whose frames can be decoded as they arrive.
public sealed class ImageDecoderRemarks
The decoding runs in tasks of the event loop of the global object, in the order of the calls of ImageDecoder.Decode. An image has one track: the frames of an animation, or its still image (an AVIF image that has both a still image and an image sequence has the track of the sequence). The frames are RGBA; their rotation and flip are the EXIF orientation of the image.
The frame count of a stream is the number of frames whose data is complete: the frames of a GIF and of an animated WebP image are counted as they arrive, the other formats are parsed again when a chunk arrives.
See also
Constructors
| Name | Description |
|---|---|
| ImageDecoder(GlobalScope, ImageDecoderInit) | Creates a decoder whose tasks run on the event loop of a global object (https://w3c.github.io/webcodecs/#dom-imagedecoder-imagedecoder). |
| ImageDecoder(ImageDecoderInit) | Creates a decoder (https://w3c.github.io/webcodecs/#dom-imagedecoder-imagedecoder). |
ImageDecoder overloads
ImageDecoder(GlobalScope, ImageDecoderInit)
ImageDecoder.csCreates a decoder whose tasks run on the event loop of a global object (https://w3c.github.io/webcodecs/#dom-imagedecoder-imagedecoder).
public ImageDecoder(GlobalScope global, ImageDecoderInit init)Parameters
globalGlobalScope- The global object (a
Windowor a worker global scope): its rendering backend decodes the image, and the tasks of the decoder run on its event loop. initImageDecoderInit- The type and the data of the image (a
byte[]or aReadOnlyMemory<T>of bytes), and the decoding options.
Exceptions
TypeErrorException- The type is not an image MIME type, the data is empty, or only one of the desired width and height is given.
ImageDecoder(ImageDecoderInit)
ImageDecoder.csCreates a decoder (https://w3c.github.io/webcodecs/#dom-imagedecoder-imagedecoder).
public ImageDecoder(ImageDecoderInit init)Parameters
initImageDecoderInit- The type and the data of the image, and the decoding options.
Exceptions
TypeErrorException- The type is not an image MIME type, the data is empty, detached, or a locked or disturbed stream, or only one of the desired width and height is given.
See also
Properties
| Name | Description |
|---|---|
| Complete | Gets whether all the data of the image has been received. |
| Completed | Gets a task that completes when all the data of the image has been received, or fails when the decoder is closed before. |
| Tracks | Gets the tracks of the image. |
| Type | Gets the MIME type given to the constructor. |
Complete
ImageDecoder.csGets whether all the data of the image has been received.
public bool Complete { get; }Completed
ImageDecoder.csGets a task that completes when all the data of the image has been received, or fails when the decoder is closed before.
public Task Completed { get; }Tracks
ImageDecoder.csGets the tracks of the image.
public ImageTrackList Tracks { get; }Type
ImageDecoder.csGets the MIME type given to the constructor.
public string Type { get; }Methods
| Name | Description |
|---|---|
| Close() | Aborts the pending decode requests and releases the resources of the decoder (https://w3c.github.io/webcodecs/#dom-imagedecoder-close): the decoder cannot be used anymore. |
| Decode(ImageDecodeOptions?) | Decodes a frame of the selected track (https://w3c.github.io/webcodecs/#dom-imagedecoder-decode). |
| IsTypeSupported(string) | Returns whether a type is a MIME type of an image the decoders support (https://w3c.github.io/webcodecs/#dom-imagedecoder-istypesupported). |
| Reset() | Aborts the pending decode requests with an AbortError (https://w3c.github.io/webcodecs/#dom-imagedecoder-reset). |
Close()
ImageDecoder.csAborts the pending decode requests and releases the resources of the decoder (https://w3c.github.io/webcodecs/#dom-imagedecoder-close): the decoder cannot be used anymore.
public void Close()Decode(ImageDecodeOptions?)
ImageDecoder.csDecodes a frame of the selected track (https://w3c.github.io/webcodecs/#dom-imagedecoder-decode).
public Task<ImageDecodeResult> Decode(ImageDecodeOptions? options = null)Parameters
optionsImageDecodeOptions?- The index of the frame.
Returns
Task<ImageDecodeResult> A task that completes with the frame once its data has been received and decoded, or fails with an InvalidStateError when the decoder is closed or no track is selected, a RangeErrorException when the image has no such frame, an EncodingError when the data is corrupted, or an AbortError when the decoder is reset or closed before.
See also
IsTypeSupported(string)
ImageDecoder.csReturns whether a type is a MIME type of an image the decoders support (https://w3c.github.io/webcodecs/#dom-imagedecoder-istypesupported).
Parameters
typestring
Returns
Task<bool> A task that completes in a task of the event loop, or fails with a TypeError when the type is not a valid image MIME type.
See also
Reset()
ImageDecoder.csAborts the pending decode requests with an AbortError (https://w3c.github.io/webcodecs/#dom-imagedecoder-reset).
public void Reset()