Table of Contents

Class ImageDecoder

Namespace
SixLabors.ImageSharp.Formats
Assembly
SixLabors.ImageSharp.dll

Acts as a base class for image decoders. Types that inherit this decoder are required to implement cancellable synchronous decoding operations only.

public abstract class ImageDecoder : IImageDecoder
Inheritance
ImageDecoder
Implements
Derived
Inherited Members

Constructors

ImageDecoder()

protected ImageDecoder()

Methods

Decode(DecoderOptions, Stream)

Decodes the image from the specified stream to an Image of a specific pixel type.

public Image Decode(DecoderOptions options, Stream stream)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

Returns

Image

The Image<TPixel>.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

Decode(DecoderOptions, Stream, CancellationToken)

Decodes the image from the specified stream to an Image.

protected abstract Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Image

The Image.

Remarks

This method is designed to support the ImageSharp internal infrastructure and is not recommended for direct use.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

DecodeAsync(DecoderOptions, Stream, CancellationToken)

Decodes the image from the specified stream to an Image of a specific pixel type.

public Task<Image> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Image>

A Task<TResult> representing the asynchronous operation.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

DecodeAsync<TPixel>(DecoderOptions, Stream, CancellationToken)

Decodes the image from the specified stream to an Image<TPixel> of a specific pixel type.

public Task<Image<TPixel>> DecodeAsync<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Image<TPixel>>

A Task<TResult> representing the asynchronous operation.

Type Parameters

TPixel

The pixel format.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

Decode<TPixel>(DecoderOptions, Stream)

Decodes the image from the specified stream to an Image<TPixel> of a specific pixel type.

public Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream) where TPixel : unmanaged, IPixel<TPixel>

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

Returns

Image<TPixel>

The Image<TPixel>.

Type Parameters

TPixel

The pixel format.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

Decode<TPixel>(DecoderOptions, Stream, CancellationToken)

Decodes the image from the specified stream to an Image<TPixel> of a specific pixel type.

protected abstract Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel<TPixel>

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Image<TPixel>

The Image<TPixel>.

Type Parameters

TPixel

The pixel format.

Remarks

This method is designed to support the ImageSharp internal infrastructure and is not recommended for direct use.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

Identify(DecoderOptions, Stream)

Reads the raw image information from the specified stream.

public ImageInfo Identify(DecoderOptions options, Stream stream)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

Returns

ImageInfo

The ImageInfo object.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

Identify(DecoderOptions, Stream, CancellationToken)

Reads the raw image information from the specified stream.

protected abstract ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

ImageInfo

The ImageInfo object.

Remarks

This method is designed to support the ImageSharp internal infrastructure and is not recommended for direct use.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

IdentifyAsync(DecoderOptions, Stream, CancellationToken)

Reads the raw image information from the specified stream.

public Task<ImageInfo> IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)

Parameters

options DecoderOptions

The general decoder options.

stream Stream

The Stream containing image data.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<ImageInfo>

The Task<TResult> object.

Exceptions

ImageFormatException

Thrown if the encoded image contains errors.

ScaleToTargetSize(DecoderOptions, Image)

Performs a scaling operation against the decoded image. If the target size is not set, or the image size already matches the target size, the image is untouched.

protected static void ScaleToTargetSize(DecoderOptions options, Image image)

Parameters

options DecoderOptions

The decoder options.

image Image

The decoded image.