ResizeOptions Class

Immutable options for ImageProcessingExtensions.Resize.

public sealed class ResizeOptions

Remarks

Output dimensions are computed with checked integer/rational arithmetic and nearest rounding, and are never smaller than one pixel. Sampling uses pixel centers and clamps at image edges.

Filtering is alpha-aware: colors are premultiplied by alpha while filtering and unpremultiplied afterward, so transparent pixels do not bleed their hidden color; pixels whose resulting alpha is zero become transparent black. 16-bit pixel formats are filtered with 16-bit precision.

Constructors

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

ResizeOptions overloads

ResizeOptions(Size)

ResizeOptions.cs

Initializes a new instance of the ResizeOptions class.

public ResizeOptions(Size size)
Parameters
size Size
The target size. Must not be empty.
Exceptions
ArgumentOutOfRangeException
size is empty.

ResizeOptions(int, int)

ResizeOptions.cs

Initializes a new instance of the ResizeOptions class.

public ResizeOptions(int width, int height)
Parameters
width int
The target width. Must be positive.
height int
The target height. Must be positive.
Exceptions
ArgumentOutOfRangeException
width or height is not positive.

Properties

NameDescription
AllowDownscalingGets a value indicating whether the image may be reduced. Defaults to true. When false, ResizeMode.Contain never goes below the original size (the image may then be larger than the target size), while ResizeMode.Stretch, ResizeMode.Cover, ResizeMode.Pad and ResizeMode.BoxPad throw an ArgumentException if the request requires a reduction, instead of returning an unexpected size.
AllowUpscalingGets a value indicating whether the image may be enlarged. Defaults to true. When false, ResizeMode.Contain, ResizeMode.Pad and ResizeMode.BoxPad never exceed the original size of the image (the padding modes still produce the target size), while ResizeMode.Stretch and ResizeMode.Cover throw an ArgumentException if the request requires enlargement, instead of returning an unexpected size.
AnchorGets the part of the image kept by ResizeMode.Cover, or where ResizeMode.Pad and ResizeMode.BoxPad place the image on the canvas. Defaults to ResizeAnchor.Center. A centered image gets the extra pixel of an odd padding on its right or bottom side.
BackgroundColorGets the color of the padding added by ResizeMode.Pad and ResizeMode.BoxPad, or null (the default) for transparent black. It is converted to the pixel format of the image, and is not used by the other modes.
FilterGets the resampling kernel. Defaults to ResamplingFilter.Bicubic.
ModeGets how the target size is interpreted. Defaults to ResizeMode.Contain.
SizeGets the target size. Its interpretation depends on ResizeOptions.Mode.
WorkingSpaceGets the numeric space used for filtering. Defaults to ResizeWorkingSpace.Encoded.

AllowDownscaling

ResizeOptions.cs

Gets a value indicating whether the image may be reduced. Defaults to true. When false, ResizeMode.Contain never goes below the original size (the image may then be larger than the target size), while ResizeMode.Stretch, ResizeMode.Cover, ResizeMode.Pad and ResizeMode.BoxPad throw an ArgumentException if the request requires a reduction, instead of returning an unexpected size.

public bool AllowDownscaling { get; init; }

Property value

bool

Remarks

ResizeMode.Contain with false enlarges an image to fit the target size but never shrinks it (a "min" resize).

AllowUpscaling

ResizeOptions.cs

Gets a value indicating whether the image may be enlarged. Defaults to true. When false, ResizeMode.Contain, ResizeMode.Pad and ResizeMode.BoxPad never exceed the original size of the image (the padding modes still produce the target size), while ResizeMode.Stretch and ResizeMode.Cover throw an ArgumentException if the request requires enlargement, instead of returning an unexpected size.

public bool AllowUpscaling { get; init; }

Property value

bool

Remarks

ResizeMode.Contain with false shrinks an image to fit the target size but never enlarges it (a "max" resize).

Gets the part of the image kept by ResizeMode.Cover, or where ResizeMode.Pad and ResizeMode.BoxPad place the image on the canvas. Defaults to ResizeAnchor.Center. A centered image gets the extra pixel of an odd padding on its right or bottom side.

public ResizeAnchor Anchor { get; init; }

Property value

ResizeAnchor

Exceptions

ArgumentOutOfRangeException
The value is not a defined ResizeAnchor.

BackgroundColor

ResizeOptions.cs

Gets the color of the padding added by ResizeMode.Pad and ResizeMode.BoxPad, or null (the default) for transparent black. It is converted to the pixel format of the image, and is not used by the other modes.

public Rgba64? BackgroundColor { get; init; }

Property value

Rgba64?

Remarks

A pixel format without alpha (PixelFormat.Rgb24, PixelFormat.Gray8, PixelFormat.Gray16) cannot store a transparent padding: padding such an image requires an opaque color.

Gets the resampling kernel. Defaults to ResamplingFilter.Bicubic.

public ResamplingFilter Filter { get; init; }

Property value

ResamplingFilter

Exceptions

ArgumentOutOfRangeException
The value is not a defined ResamplingFilter.

Gets how the target size is interpreted. Defaults to ResizeMode.Contain.

public ResizeMode Mode { get; init; }

Property value

ResizeMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined ResizeMode.

Gets the target size. Its interpretation depends on ResizeOptions.Mode.

public Size Size { get; }

Property value

Size

WorkingSpace

ResizeOptions.cs

Gets the numeric space used for filtering. Defaults to ResizeWorkingSpace.Encoded.

public ResizeWorkingSpace WorkingSpace { get; init; }

Property value

ResizeWorkingSpace

Exceptions

ArgumentOutOfRangeException
The value is not a defined ResizeWorkingSpace.