ImageWriterOptions Class

Immutable options for Image.CreateWriter.

public sealed class ImageWriterOptions

Remarks

The writer takes a snapshot of these options when it is created: later changes to the ImageWriterOptions.Metadata or ImageWriterOptions.Animation instances passed here do not affect the writer.

Constructors

NameDescription
ImageWriterOptions(Size)Initializes a new instance of the ImageWriterOptions class.
ImageWriterOptions(int, int)Initializes a new instance of the ImageWriterOptions class.

ImageWriterOptions overloads

ImageWriterOptions(Size)

ImageWriterOptions.cs

Initializes a new instance of the ImageWriterOptions class.

public ImageWriterOptions(Size canvasSize)
Parameters
canvasSize Size
The size of every frame written. Must not be empty.
Exceptions
ArgumentOutOfRangeException
canvasSize is empty.

ImageWriterOptions(int, int)

ImageWriterOptions.cs

Initializes a new instance of the ImageWriterOptions class.

public ImageWriterOptions(int width, int height)
Parameters
width int
The width of every frame written. Must be positive.
height int
The height of every frame written. Must be positive.
Exceptions
ArgumentOutOfRangeException
width or height is not positive.

Properties

NameDescription
AnimationGets the animation-wide settings (such as the number of plays), or null for defaults. When null and more than one frame or a poster frame is written, an infinitely looping animation is produced. The writer copies it when it is created.
CanvasSizeGets the size of every frame written.
ConfigurationGets the configuration of the writer (resource limits, parallelism). Defaults to ImageConfiguration.Default.
EncoderGets the encoder and its settings. Required for stream outputs. For path outputs, null selects the encoder from the file extension, like Image.Save.
ExpectedFrameCountGets the number of displayed frames that will be written (excluding a poster frame), or null if unknown. PNG/APNG, AVIF and HEIC output require a known count; GIF supports an unknown count; JPEG output requires exactly one frame. ImageWriter<TPixel>.Complete fails if the actual count differs.
LeaveOpenGets a value indicating whether a caller-provided stream is left open when the writer is disposed. Defaults to true. Streams opened by the path overloads are always owned by the writer.
MetadataGets the image-wide metadata to write, or null to write none. The writer copies it when it is created.

Gets the animation-wide settings (such as the number of plays), or null for defaults. When null and more than one frame or a poster frame is written, an infinitely looping animation is produced. The writer copies it when it is created.

public AnimationMetadata? Animation { get; init; }

Property value

AnimationMetadata?

Gets the size of every frame written.

public Size CanvasSize { get; }

Property value

Size

Gets the configuration of the writer (resource limits, parallelism). Defaults to ImageConfiguration.Default.

public ImageConfiguration Configuration { get; init; }

Property value

ImageConfiguration

Exceptions

ArgumentNullException
The value is null.

Gets the encoder and its settings. Required for stream outputs. For path outputs, null selects the encoder from the file extension, like Image.Save.

public ImageEncoder? Encoder { get; init; }

Property value

ImageEncoder?

ExpectedFrameCount

ImageWriterOptions.cs

Gets the number of displayed frames that will be written (excluding a poster frame), or null if unknown. PNG/APNG, AVIF and HEIC output require a known count; GIF supports an unknown count; JPEG output requires exactly one frame. ImageWriter<TPixel>.Complete fails if the actual count differs.

public int? ExpectedFrameCount { 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 writer is disposed. Defaults to true. Streams opened by the path overloads are always owned by the writer.

public bool LeaveOpen { get; init; }

Property value

bool

Gets the image-wide metadata to write, or null to write none. The writer copies it when it is created.

public ImageMetadata? Metadata { get; init; }

Property value

ImageMetadata?