PeachImage

PeachImage

ImageDecoder Class

Decodes images into memory the caller owns, so a hot loop (a thumbnailer, a tile server) decodes into one reusable buffer instead of getting a fresh Image per call. Create one per thread; an instance is not safe for concurrent use.

public sealed class ImageDecoder : System.IDisposable

Inheritance System.Object → ImageDecoder

Implements System.IDisposable

Remarks

The destination holds the decoded pixels in the format the image decodes to, or TargetPixelFormat when set; the returned ImageInfo says which. ScaleDenominator, TargetSize, ApplyOrientation and the size limits behave as they do for Load(Stream, DecoderOptions), and GetRequiredBufferSize(DecoderOptions, int) accounts for them. An animated source decodes its first frame.

Metadata comes back through the metadata parameter. With SkipMetadata set it is empty and none is parsed.

Constructors  
ImageDecoder(DecoderOptions) Creates a decoder that applies options to every call.
Methods  
DecodeInto(Stream, Span<byte>, ImageMetadata, int) Decodes the image at stream’s position into destination; see DecodeInto(ReadOnlySpan<byte>, Span<byte>, ImageMetadata, int).
DecodeInto(ReadOnlySpan<byte>, Span<byte>, ImageMetadata, int) Decodes data into destination, rows rowStride bytes apart (0, the default, packs them tightly).
Dispose() Releases the decoder; further calls throw System.ObjectDisposedException.
TryDecodeInto(ReadOnlySpan<byte>, Span<byte>, ImageInfo, ImageMetadata, int) Like DecodeInto(ReadOnlySpan<byte>, Span<byte>, ImageMetadata, int), but returns false instead of throwing when destination is too small. Nothing is decoded then, info is the header’s own description (so info.GetRequiredBufferSize(options, rowStride) gives the size needed) and metadata is empty. A damaged or unsupported image still throws.