ImageReaderOptions Class

Immutable options for Image.OpenReader.

public sealed class ImageReaderOptions

Constructors

NameDescription
ImageReaderOptions()

ImageReaderOptions()

ImageReaderOptions.cs
public ImageReaderOptions()

No documentation is available.

Properties

NameDescription
CmykConversionGets the color conversion applied to images whose samples are CMYK inks (four-component JPEG), or null (the default) to reject them with an UnsupportedImageFeatureException.
ConfigurationGets the configuration of the reader. Its resource limits apply to the whole input, and images returned by the reader are charged to the reader's allocation scope until they are disposed. Defaults to ImageConfiguration.Default.
ConversionGets the options used to convert decoded samples to the reader's pixel type. Defaults to PixelConversionOptions.Default.
DefaultGets the default options.
FrameLimitGets the maximum number of displayed frames to read, or null to read all frames. Once the limit is reached, the reader reports a clean end of input without examining the remaining data.
LeaveOpenGets a value indicating whether a caller-provided stream is left open when the reader is disposed. Defaults to true. Streams opened by the path overloads are always owned and closed by the reader.
ScaleDenominatorGets the factor by which the decoder divides the width and the height of the image, a power of two. Defaults to 1: the image is decoded at full resolution.
TargetSizeGets the smallest size the decoder needs to produce, or null (the default) to decode at full resolution. A file that can be decoded at a reduced resolution is decoded at the largest ImageReaderOptions.ScaleDenominator it allows whose size is still at least this size in both dimensions; any other file is decoded at full resolution.

CmykConversion

ImageReaderOptions.cs

Gets the color conversion applied to images whose samples are CMYK inks (four-component JPEG), or null (the default) to reject them with an UnsupportedImageFeatureException.

public CmykConversionOptions? CmykConversion { get; init; }

Property value

CmykConversionOptions?

Remarks

No pixel format holds CMYK samples, so such an image can only be loaded by converting its colors. Like every color conversion it is explicit: set new CmykConversionOptions() to convert to sRGB. Other images are not affected.

Gets the configuration of the reader. Its resource limits apply to the whole input, and images returned by the reader are charged to the reader's allocation scope until they are disposed. Defaults to ImageConfiguration.Default.

public ImageConfiguration Configuration { get; init; }

Property value

ImageConfiguration

Exceptions

ArgumentNullException
The value is null.

Gets the options used to convert decoded samples to the reader's pixel type. Defaults to PixelConversionOptions.Default.

public PixelConversionOptions Conversion { get; init; }

Property value

PixelConversionOptions

Exceptions

ArgumentNullException
The value is null.

Gets the default options.

public static ImageReaderOptions Default { get; }

Property value

ImageReaderOptions

Gets the maximum number of displayed frames to read, or null to read all frames. Once the limit is reached, the reader reports a clean end of input without examining the remaining data.

public int? FrameLimit { get; init; }

Property value

int?

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Gets a value indicating whether a caller-provided stream is left open when the reader is disposed. Defaults to true. Streams opened by the path overloads are always owned and closed by the reader.

public bool LeaveOpen { get; init; }

Property value

bool

ScaleDenominator

ImageReaderOptions.cs

Gets the factor by which the decoder divides the width and the height of the image, a power of two. Defaults to 1: the image is decoded at full resolution.

public int ScaleDenominator { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not a positive power of two.
ArgumentException
The value is not 1 and ImageReaderOptions.TargetSize is set.

Remarks

The decoded image has ceil(width / ScaleDenominator) by ceil(height / ScaleDenominator) pixels, computed from fewer samples than a full decode, for less time and memory, by the formats that support it (see the format reference of the readme). The pixels are close to a resize of the full image, not equal to it. The metadata is the one of the file, like after a resize.

A file that cannot be decoded at this scale (a format that only decodes at full resolution, or a scale that the file does not allow) is an UnsupportedImageFeatureException. Set ImageReaderOptions.TargetSize instead to get the smallest image the file allows without failing. The two properties cannot be set together.

Gets the smallest size the decoder needs to produce, or null (the default) to decode at full resolution. A file that can be decoded at a reduced resolution is decoded at the largest ImageReaderOptions.ScaleDenominator it allows whose size is still at least this size in both dimensions; any other file is decoded at full resolution.

public Size? TargetSize { get; init; }

Property value

Size?

Exceptions

ArgumentOutOfRangeException
The width or the height of the value is zero.
ArgumentException
The value is not null and ImageReaderOptions.ScaleDenominator is not 1.

Remarks

The size is compared with the stored dimensions of the image, before its orientation is applied. The decoded image is usually larger than the target: resize it afterwards to get an exact size. For a thumbnail, this is much faster than resizing a full decode, with nearly the same result.