Price: US$79.00

Pay securely at PayPal. On the confirmation page, click Continue to product download page to download this product immediately.

Having a PayPal account is optional; if you don't want to sign up, look for the link which says Don't have a PayPal account?

Ultimate Image Resizer

API Documentation

UltimateImageResizer.IImageResizer

A component which resizes images.

Properties

NameDescription

Property

Mode

Specifies how images will be resized when the aspect ratio of the desired image size is different to the source image's aspect ratio. For example, when a square image is to be resized to a rectangular size, this value determines how to fit the square image into the rectangular bounds. The default is ResizeMode.KeepOriginalRatio.

Property

PaddingColor

Specifies the color to use for padding when IImageResizer.Mode is equal to ResizeMode.KeepOriginalRatioByPadding. The default is Color.White.

Property

Image

Gets the underlying image that is being resized.

Methods

NameDescription

Method

Load (System.Drawing.Bitmap image)

Loads an image into the resizer.

Parameters

image: An image to be resized.

Exceptions

System.ArgumentNullException: The image parameter is null.

System.ArgumentException: The image does not reference a valid image file.

Method

Load (System.String filePath)

Loads an image into the resizer. The file is loaded into memory and so the file will not be locked.

Parameters

filePath: The path to the image file to open.

Exceptions

System.ArgumentNullException: The file path is null.

System.IO.FileNotFoundException: The file path does not exist.

System.ArgumentException: The file exists but is not a valid image file. This may happen if the path points to a non-image file, or if the image format is not supported by the .NET libraries.

Method

Load (System.IO.Stream stream)

Loads an image into the resizer.

Parameters

stream: A stream containing the image data.

Exceptions

System.ArgumentNullException: The stream parameter is null.

System.ArgumentException: The stream does not point to a valid image file.

Method

Load (System.Byte[] imageBytes)

Loads an image into the resizer.

Parameters

imageBytes: An array of bytes which make an image.

Exceptions

System.ArgumentNullException: The imageBytes parameter is null.

System.ArgumentException: The bytes are not a valid image file.

Method

Load (System.Uri uri)

Loads an image into the resizer from a URI. This can be used to load images from the web.

Parameters

uri: A URI of a valid image file.

Exceptions

System.ArgumentNullException: The URI parameter is null.

System.ArgumentException: The URI does not point to a valid image file.

System.Net.WebException: There was an error while downloading the file. This may occur if the file does not exist or there is no internet connection available.

Method

SaveToDisk (OutputImageFormat format, System.String path)

Saves the image in the given format to the disk.

Parameters

format: The format to save as.

path: The full path to the file to be saved. If no file extension is specified, or the file extension does not match the output format, then a file extension will be added automatically. If the directory does not exist, it will be created. If the file already exists, it will be overwritten.

Return Value

Returns a FileInfo pointing to the newly-saved image on disk.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

System.ArgumentNullException: The path is null.

System.Security.SecurityException: The caller does not have the required permission.

System.ArgumentException: The file name is empty, contains only white spaces, or contains invalid characters.

System.UnauthorizedAccessException: Access to the path is denied.

System.IO.PathTooLongException: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.NotSupportedException: The path contains a colon (:) in the middle of the string.

Method

GetBytes (OutputImageFormat format)

Gets the image as an array of bytes.

Parameters

format: The format of the image to get.

Return Value

Returns the image as an array of bytes.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

Method

GetStream (OutputImageFormat format)

Gets the image as a stream.

Parameters

format: The format of the image to get.

Return Value

Returns the image as a MemoryStream.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

Method

Resize (System.Drawing.Size targetSize)

Resizes the image to the given target size. The actual size may be different from the target size depending on the value chosen for the IImageResizer.Mode property.

Parameters

targetSize: The desired size in pixels to resize the input image to.

Return Value

Returns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

System.ArgumentException: The width or height is less than 1 pixel.

Method

Resize (System.Int32 targetWidth, System.Int32 targetHeight)

Resizes the image to the given target size. The actual size may be different from the target size depending on the value chosen for the IImageResizer.Mode property.

Parameters

targetWidth: The desired size in pixels to resize the input image width to.

targetHeight: The desired size in pixels to resize the input image height to.

Return Value

Returns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

System.ArgumentException: The width or height is less than 1 pixel.

Method

CalculateActualSize (System.Drawing.Size currentSize, System.Drawing.Size targetSize)

Returns the size that the current image would be resized to given the current settings of the resizer and the target resize amount. This is useful if you need to know what size an image will be without actually resizing the underlying image.

Parameters

currentSize: The size of the current image. To use the currently-loaded image size, pass the Size property of this resizer's IImageResizer.Image property.

targetSize: The size to use as the desired resize value.

Return Value

Returns the size that the image would be resized to if IImageResizer.Resize(System.Drawing.Size) was called. In most cases, the return size will be the same as the target size, unless the IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.ArgumentException: The width or height is less than 1 pixel.

Method

CalculateActualSize (System.Int32 currentWidth, System.Int32 currentHeight, System.Int32 targetWidth, System.Int32 targetHeight)

Returns the size that the current image would be resized to given the current settings of the resizer and the target resize amount. This is useful if you need to know what size an image will be without actually resizing the underlying image.

Parameters

currentWidth: The width of the current image. To use the currently-loaded image width, pass the Width property of this resizer's IImageResizer.Image property.

currentHeight: The height of the current image. To use the currently-loaded image height, pass the Height property of this resizer's IImageResizer.Image property.

targetWidth: The size to use as the desired resize-width value.

targetHeight: The size to use as the desired resize-height value.

Return Value

Returns the size that the image would be resized to if IImageResizer.Resize(System.Drawing.Size) was called. In most cases, the return size will be the same as the target size, unless the IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.ArgumentException: The width or height is less than 1 pixel.

Method

RotateIfNeeded ()

Rotates the image so that it is the right way up if the image was taken in portrait mode and it has not been rotated. If also resizing, this method must be called before resizing.

Return Value

Returns the type of rotation that was applied. If the image was not rotated, this will be RotateFlipType.RotateNoneFlipNone.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

UltimateImageResizer.ImageResizer

A component which resizes images.

Constructors

NameDescription

Method

ImageResizer ()

Creates an image resizer with no image loaded. One of the overloaded Load methods (e.g. ImageResizer.Load(System.String)) will need to be called before any other methods are called.

Method

ImageResizer (System.Drawing.Bitmap image)

Creates a new image resizer using the given image as the resize target.

Parameters

image: An image to be resized.

Exceptions

System.ArgumentNullException: The image parameter is null.

System.ArgumentException: The image does not reference a valid image file.

Method

ImageResizer (System.String sourceImageFilePath)

Creates a new image resizer by loading the given file into memory.

Parameters

sourceImageFilePath: The path to the image file to open.

Exceptions

System.ArgumentNullException: The file path is null.

System.IO.FileNotFoundException: The file path does not exist.

System.ArgumentException: The file exists but is not a valid image file. This may happen if the path points to a non-image file, or if the image format is not supported by the .NET libraries.

Method

ImageResizer (System.IO.Stream imageStream)

Creates a new image resizer by loading an image from the given stream.

Parameters

imageStream: A stream containing image data.

Exceptions

System.ArgumentNullException: The stream parameter is null.

System.ArgumentException: The stream does not point to a valid image file.

Method

ImageResizer (System.Byte[] imageBytes)

Creates a new image resizer using the given byte array.

Parameters

imageBytes: An array of bytes which make an image.

Exceptions

System.ArgumentNullException: The imageBytes parameter is null.

System.ArgumentException: The bytes are not a valid image file.

Properties

NameDescription

Property

Mode

Specifies how images will be resized when the aspect ratio of the desired image size is different to the source image's aspect ratio. For example, when a square image is to be resized to a rectangular size, this value determines how to fit the square image into the rectangular bounds. The default is ResizeMode.KeepOriginalRatio.

Property

PaddingColor

Specifies the color to use for padding when ImageResizer.Mode is equal to ResizeMode.KeepOriginalRatioByPadding. The default is Color.White.

Property

Image

Gets the underlying image that is being resized.

Methods

NameDescription

Method

Load (System.Drawing.Bitmap image)

Loads an image into the resizer.

Parameters

image: An image to be resized.

Exceptions

System.ArgumentNullException: The image parameter is null.

System.ArgumentException: The image does not reference a valid image file.

Method

Load (System.String filePath)

Loads an image into the resizer. The file is loaded into memory and so the file will not be locked.

Parameters

filePath: The path to the image file to open.

Exceptions

System.ArgumentNullException: The file path is null.

System.IO.FileNotFoundException: The file path does not exist.

System.ArgumentException: The file exists but is not a valid image file. This may happen if the path points to a non-image file, or if the image format is not supported by the .NET libraries.

Method

Load (System.IO.Stream stream)

Loads an image into the resizer.

Parameters

stream: A stream containing image data.

Exceptions

System.ArgumentNullException: The stream parameter is null.

System.ArgumentException: The stream does not point to a valid image file.

Method

Load (System.Byte[] imageBytes)

Loads an image into the resizer.

Parameters

imageBytes: An array of bytes which make an image.

Exceptions

System.ArgumentNullException: The imageBytes parameter is null.

System.ArgumentException: The bytes are not a valid image file.

Method

Load (System.Uri uri)

Loads an image into the resizer from a URI. This can be used to load images from the web.

Parameters

uri: A URI of a valid image file.

Exceptions

System.ArgumentNullException: The URI parameter is null.

System.ArgumentException: The URI does not point to a valid image file.

System.Net.WebException: There was an error while downloading the file. This may occur if the file does not exist or there is no internet connection available.

Method

SaveToDisk (OutputImageFormat format, System.String path)

Saves the image in the given format to the disk.

Parameters

format: The format to save as.

path: The full path to the file to be saved. If no file extension is specified, or the file extension does not match the output format, then a file extension will be added automatically. If the directory does not exist, it will be created. If the file already exists, it will be overwritten.

Return Value

Returns a FileInfo pointing to the newly-saved image on disk.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

System.ArgumentNullException: The path is null.

System.Security.SecurityException: The caller does not have the required permission.

System.ArgumentException: The file name is empty, contains only white spaces, or contains invalid characters.

System.UnauthorizedAccessException: Access to the path is denied.

System.IO.PathTooLongException: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.NotSupportedException: The path contains a colon (:) in the middle of the string.

Method

GetBytes (OutputImageFormat format)

Gets the image as an array of bytes.

Parameters

format: The format of the image to get.

Return Value

Returns the image as an array of bytes.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

Method

GetStream (OutputImageFormat format)

Gets the image as a stream.

Parameters

format: The format of the image to get.

Return Value

Returns the image as a MemoryStream.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

MethodStatic

CreateEncoderParameters ()

Gets the parameters for the image encoder.

MethodStatic

GetCodec (OutputImageFormat format)

Gets the codec for the given image format.

Parameters

format: The image format to get the codec for.

Method

Resize (System.Drawing.Size targetSize)

Resizes the image to the given target size. The actual size may be different from the target size depending on the value chosen for the ImageResizer.Mode property.

Parameters

targetSize: The desired size to resize the input image to.

Return Value

Returns the actual size that the image has been resized to. This may be different from the target size when ImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

Method

Resize (System.Int32 targetWidth, System.Int32 targetHeight)

Resizes the image to the given target size. The actual size may be different from the target size depending on the value chosen for the IImageResizer.Mode property.

Parameters

targetWidth: The desired size in pixels to resize the input image width to.

targetHeight: The desired size in pixels to resize the input image height to.

Return Value

Returns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

System.ArgumentException: The width or height is less than 1 pixel.

Method

CalculateActualSize (System.Drawing.Size currentSize, System.Drawing.Size targetSize)

Returns the size that the current image would be resized to given the current settings of the resizer and the target resize amount. This is useful if you need to know what size an image will be without actually resizing the underlying image.

Parameters

currentSize: The size of the current image. To use the currently-loaded image size, pass the Size property of this resizer's IImageResizer.Image property.

targetSize: The size to use as the desired resize value.

Return Value

Returns the size that the image would be resized to if IImageResizer.Resize(System.Drawing.Size) was called. In most cases, the return size will be the same as the target size, unless the IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.ArgumentException: The width or height is less than 1 pixel.

Method

CalculateActualSize (System.Int32 currentWidth, System.Int32 currentHeight, System.Int32 targetWidth, System.Int32 targetHeight)

Returns the size that the current image would be resized to given the current settings of the resizer and the target resize amount. This is useful if you need to know what size an image will be without actually resizing the underlying image.

Parameters

currentWidth: The width of the current image. To use the currently-loaded image width, pass the Width property of this resizer's IImageResizer.Image property.

currentHeight: The height of the current image. To use the currently-loaded image height, pass the Height property of this resizer's IImageResizer.Image property.

targetWidth: The size to use as the desired resize-width value.

targetHeight: The size to use as the desired resize-height value.

Return Value

Returns the size that the image would be resized to if IImageResizer.Resize(System.Drawing.Size) was called. In most cases, the return size will be the same as the target size, unless the IImageResizer.Mode is ResizeMode.KeepOriginalRatio.

Exceptions

System.ArgumentException: The width or height is less than 1 pixel.

Method

RotateIfNeeded ()

Rotates the image so that it is the right way up if the image was taken in portrait mode and it has not been rotated. If also resizing, this method must be called before resizing.

Return Value

Returns the type of rotation that was applied. If the image was not rotated, this will be RotateFlipType.RotateNoneFlipNone.

Exceptions

System.InvalidOperationException: No file has been loaded in memory. Call Load first.

Method

Dispose ()

Releases the image which is being operated on.

UltimateImageResizer.OutputImageFormat

Specifies the image format to save the resized image as. This can be the same as the input image, or a specific format such as JPEG.

NameDescription

Field

Jpeg

The resized image will be a JPEG image.

Field

Gif

The resized image will be a GIF image. Please note that transparency and animated GIFs are not supported.

Field

Png

The resized image will be a PNG image.

Field

Bmp

The resized image will be a window Bitmap image. These are generally very large and not recommended.

UltimateImageResizer.ResizeMode

Specifies how images will be resized when the aspect ratio of the desired image size is different to the source image's aspect ratio. For example, when a square image is to be resized to a rectangular size, this value determines how to fit the square image into the rectangular bounds.

NameDescription

Field

StretchImage

The original image will be squashed to fit into the target size. This may result in unattractive images and is not recommended.

Field

KeepOriginalRatio

The image will be resized, keeping it's original aspect ratio. The resulting image will either be shorter or thinner than the requested size. This is useful when the image is shown independantly of other images, for example on a detail page. It may not be suitable for a list of thumbnails as each image will be potentially resized to a different size.

Field

KeepOriginalRatioByPadding

The image will be resized, keeping it's original aspect ratio. In order to ensure that the output image is the same size as the requested size, extra space around the image will be added. This is useful when you are listing thumbnails and want to keep the original image's aspect ratio without cropping the image.

The disadvantage is that a fixed color will be added to the side of the image, perhaps making ResizeMode.KeepOriginalRatioByCropping a more suitable choice. The color of the padding is configurable, as is the placement of the resized image in relation to the added padding.

Field

KeepOriginalRatioByCropping

The image will be resized, with some of the image cropped so that the resized image is the same size as the target size, and there is no empty space. An image which is wide may have the sides cut off; an image that is tall may have the top or bottom cut off. This is suitable for thumbnail lists where you want every image to be the same size as each other.