Devesprit.ImageProcessor & Devesprit.ImageServer
Resize

Description:

Resizes the current image to the given dimensions. If EXIF meta data is to be preserved the information contained within will also be updated to match.

Method Declaration
Copy Code
public ImageFactory Resize(Size size)

Parameters:

size The System.Drawing.Size containing the width and height to set the image to. Passing a 0 for either dimension will omit that dimension.



Method Declaration
Copy Code
public ImageFactory Resize(ResizeLayer resizeLayer)

ResizeLayer:

Size The System.Drawing.Size containing the width and height to set the image to. Passing a 0 for either dimension will omit that dimension.
ResizeMode The Devesprit.ImageProcessor.Imaging.ResizeMode to apply to resized image.
AnchorPosition The Devesprit.ImageProcessor.Imaging.AnchorPosition to apply to resized image. Applies to ResizeMode.Pad, ResizeMode.BoxPad, and ResizeMode.Crop.
UpScale Whether to allow up-scaling of images. Defaults to true.

When resizing using the Resize(Size size) overload the default resize mode is ResizeMode.Pad.

Assembly:

Devesprit.ImageProcessor

Example:

Original



Resize Pad

Resizes the image to the given dimensions. If the set dimensions do not match the aspect ratio of the original image then the output is padded to match the new aspect ratio. Passing a single dimension will automatically preserve the aspect ratio of the original image.

Any padded areas in the output for image formats that do not contain an alpha channel will be displayed as black (the default encoder output). To change this color to another use the BackgroundColor method.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.Pad, AnchorPosition.Center, true));



Resize BoxPad

When up scaling an image the image pixels themselves are not resized, rather the image is padded to fit the given dimensions. When downscaling the image is resized using the rules defined by ResizeMode.Pad.

Any padded areas in the output for image formats that do not contain an alpha channel will be displayed as black (the default encoder output). To change this color to another use the BackgroundColor method.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.BoxPad, AnchorPosition.Center, true));



Resize Crop

Resizes the image to the given dimensions. If the set dimensions do not match the aspect ratio of the original image then the output is cropped to match the new aspect ratio.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.Crop, AnchorPosition.Center, true));



Resize Min

Resizes the image until the shortest side reaches the set given dimension. This will maintain the aspect ratio of the original image. Up Scaling is disabled in this mode and the original image will be returned if attempted.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.Min, AnchorPosition.Center, true));



Resize Max

Resizes the image to the given dimensions. If the set dimensions do not match the aspect ratio of the original image then the output is resized to the maximum possible value in each direction while maintaining the original aspect ratio.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.Max, AnchorPosition.Center, true));



Resize Stretch

Resizes the image to the given dimensions. If the set dimensions do not match the aspect ratio of the original image then the output is stretched to match the new aspect ratio.

Example
Copy Code
new ImageFactory().Load(@"My-Image-Path")
.Resize(new ResizeLayer(new Size(500, 500), ResizeMode.Stetch, AnchorPosition.Center, true));

See Also