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
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
optionsDecoderOptionsThe general decoder options.
streamStreamThe 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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe 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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image<TPixel>>
A Task<TResult> representing the asynchronous operation.
Type Parameters
TPixelThe 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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
Returns
- Image<TPixel>
The Image<TPixel>.
Type Parameters
TPixelThe 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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Image<TPixel>
The Image<TPixel>.
Type Parameters
TPixelThe 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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
Returns
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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
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
optionsDecoderOptionsThe general decoder options.
streamStreamThe Stream containing image data.
cancellationTokenCancellationTokenThe 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
optionsDecoderOptionsThe decoder options.
imageImageThe decoded image.