ResizeOptions Class
Immutable options for ImageProcessingExtensions.Resize.
public sealed class ResizeOptionsRemarks
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
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the ResizeOptions class.
public ResizeOptions(Size size)Parameters
sizeSize- The target size. Must not be empty.
Exceptions
ArgumentOutOfRangeExceptionsizeis empty.
ResizeOptions(int, int)
ResizeOptions.csInitializes a new instance of the ResizeOptions class.
Properties
| Name | Description |
|---|---|
| AllowDownscaling | 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. |
| AllowUpscaling | 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. |
| Anchor | 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. |
| BackgroundColor | 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. |
| Filter | Gets the resampling kernel. Defaults to ResamplingFilter.Bicubic. |
| Mode | Gets how the target size is interpreted. Defaults to ResizeMode.Contain. |
| Size | Gets the target size. Its interpretation depends on ResizeOptions.Mode. |
| WorkingSpace | Gets the numeric space used for filtering. Defaults to ResizeWorkingSpace.Encoded. |
AllowDownscaling
ResizeOptions.csGets 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
Remarks
ResizeMode.Contain with false enlarges an image to fit the target size but never shrinks it (a "min" resize).
AllowUpscaling
ResizeOptions.csGets 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
Remarks
ResizeMode.Contain with false shrinks an image to fit the target size but never enlarges it (a "max" resize).
Anchor
ResizeOptions.csGets 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; }BackgroundColor
ResizeOptions.csGets 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
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.
Filter
ResizeOptions.csGets the resampling kernel. Defaults to ResamplingFilter.Bicubic.
public ResamplingFilter Filter { get; init; }Mode
ResizeOptions.csGets how the target size is interpreted. Defaults to ResizeMode.Contain.
public ResizeMode Mode { get; init; }Size
ResizeOptions.csGets the target size. Its interpretation depends on ResizeOptions.Mode.
public Size Size { get; }Property value
WorkingSpace
ResizeOptions.csGets the numeric space used for filtering. Defaults to ResizeWorkingSpace.Encoded.
public ResizeWorkingSpace WorkingSpace { get; init; }