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
| Name | Description | |
|---|---|---|
| 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. |
| PaddingColor |
Specifies the color to use for padding when IImageResizer.Mode is equal to ResizeMode.KeepOriginalRatioByPadding. The default is Color.White. |
| Image |
Gets the underlying image that is being resized. |
Methods
| Name | Description | |
|---|---|---|
| Load (System.Drawing.Bitmap image) | Loads an image into the resizer. Parametersimage: An image to be resized. ExceptionsSystem.ArgumentNullException: The image parameter is null. System.ArgumentException: The image does not reference a valid image file. |
| Load (System.String filePath) | Loads an image into the resizer. The file is loaded into memory and so the file will not be locked. ParametersfilePath: The path to the image file to open. ExceptionsSystem.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. |
| Load (System.IO.Stream stream) | Loads an image into the resizer. Parametersstream: A stream containing the image data. ExceptionsSystem.ArgumentNullException: The stream parameter is null. System.ArgumentException: The stream does not point to a valid image file. |
| Load (System.Byte[] imageBytes) | Loads an image into the resizer. ParametersimageBytes: An array of bytes which make an image. ExceptionsSystem.ArgumentNullException: The imageBytes parameter is null. System.ArgumentException: The bytes are not a valid image file. |
| Load (System.Uri uri) | Loads an image into the resizer from a URI. This can be used to load images from the web. Parametersuri: A URI of a valid image file. ExceptionsSystem.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. |
| SaveToDisk (OutputImageFormat format, System.String path) | Saves the image in the given format to the disk. Parametersformat: 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 ValueReturns a FileInfo pointing to the newly-saved image on disk. ExceptionsSystem.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. |
| GetBytes (OutputImageFormat format) | Gets the image as an array of bytes. Parametersformat: The format of the image to get. Return ValueReturns the image as an array of bytes. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| GetStream (OutputImageFormat format) | Gets the image as a stream. Parametersformat: The format of the image to get. Return ValueReturns the image as a MemoryStream. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| 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. ParameterstargetSize: The desired size in pixels to resize the input image to. Return ValueReturns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. System.ArgumentException: The width or height is less than 1 pixel. |
| 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. ParameterstargetWidth: 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 ValueReturns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. System.ArgumentException: The width or height is less than 1 pixel. |
| 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. ParameterscurrentSize: 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 ValueReturns 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. ExceptionsSystem.ArgumentException: The width or height is less than 1 pixel. |
| 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. ParameterscurrentWidth: 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 ValueReturns 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. ExceptionsSystem.ArgumentException: The width or height is less than 1 pixel. |
| 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 ValueReturns the type of rotation that was applied. If the image was not rotated, this will be RotateFlipType.RotateNoneFlipNone. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
UltimateImageResizer.ImageResizer
A component which resizes images.
Constructors
| Name | Description | |
|---|---|---|
| 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. |
| ImageResizer (System.Drawing.Bitmap image) | Creates a new image resizer using the given image as the resize target. Parametersimage: An image to be resized. ExceptionsSystem.ArgumentNullException: The image parameter is null. System.ArgumentException: The image does not reference a valid image file. |
| ImageResizer (System.String sourceImageFilePath) | Creates a new image resizer by loading the given file into memory. ParameterssourceImageFilePath: The path to the image file to open. ExceptionsSystem.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. |
| ImageResizer (System.IO.Stream imageStream) | Creates a new image resizer by loading an image from the given stream. ParametersimageStream: A stream containing image data. ExceptionsSystem.ArgumentNullException: The stream parameter is null. System.ArgumentException: The stream does not point to a valid image file. |
| ImageResizer (System.Byte[] imageBytes) | Creates a new image resizer using the given byte array. ParametersimageBytes: An array of bytes which make an image. ExceptionsSystem.ArgumentNullException: The imageBytes parameter is null. System.ArgumentException: The bytes are not a valid image file. |
Properties
| Name | Description | |
|---|---|---|
| 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. |
| PaddingColor |
Specifies the color to use for padding when ImageResizer.Mode is equal to ResizeMode.KeepOriginalRatioByPadding. The default is Color.White. |
| Image |
Gets the underlying image that is being resized. |
Methods
| Name | Description | |
|---|---|---|
| Load (System.Drawing.Bitmap image) | Loads an image into the resizer. Parametersimage: An image to be resized. ExceptionsSystem.ArgumentNullException: The image parameter is null. System.ArgumentException: The image does not reference a valid image file. |
| Load (System.String filePath) | Loads an image into the resizer. The file is loaded into memory and so the file will not be locked. ParametersfilePath: The path to the image file to open. ExceptionsSystem.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. |
| Load (System.IO.Stream stream) | Loads an image into the resizer. Parametersstream: A stream containing image data. ExceptionsSystem.ArgumentNullException: The stream parameter is null. System.ArgumentException: The stream does not point to a valid image file. |
| Load (System.Byte[] imageBytes) | Loads an image into the resizer. ParametersimageBytes: An array of bytes which make an image. ExceptionsSystem.ArgumentNullException: The imageBytes parameter is null. System.ArgumentException: The bytes are not a valid image file. |
| Load (System.Uri uri) | Loads an image into the resizer from a URI. This can be used to load images from the web. Parametersuri: A URI of a valid image file. ExceptionsSystem.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. |
| SaveToDisk (OutputImageFormat format, System.String path) | Saves the image in the given format to the disk. Parametersformat: 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 ValueReturns a FileInfo pointing to the newly-saved image on disk. ExceptionsSystem.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. |
| GetBytes (OutputImageFormat format) | Gets the image as an array of bytes. Parametersformat: The format of the image to get. Return ValueReturns the image as an array of bytes. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| GetStream (OutputImageFormat format) | Gets the image as a stream. Parametersformat: The format of the image to get. Return ValueReturns the image as a MemoryStream. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| CreateEncoderParameters () | Gets the parameters for the image encoder. |
| GetCodec (OutputImageFormat format) | Gets the codec for the given image format. Parametersformat: The image format to get the codec for. |
| 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. ParameterstargetSize: The desired size to resize the input image to. Return ValueReturns the actual size that the image has been resized to. This may be different from the target size when ImageResizer.Mode is ResizeMode.KeepOriginalRatio. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| 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. ParameterstargetWidth: 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 ValueReturns the actual size that the image has been resized to. This may be different from the target size when IImageResizer.Mode is ResizeMode.KeepOriginalRatio. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. System.ArgumentException: The width or height is less than 1 pixel. |
| 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. ParameterscurrentSize: 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 ValueReturns 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. ExceptionsSystem.ArgumentException: The width or height is less than 1 pixel. |
| 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. ParameterscurrentWidth: 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 ValueReturns 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. ExceptionsSystem.ArgumentException: The width or height is less than 1 pixel. |
| 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 ValueReturns the type of rotation that was applied. If the image was not rotated, this will be RotateFlipType.RotateNoneFlipNone. ExceptionsSystem.InvalidOperationException: No file has been loaded in memory. Call Load first. |
| 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.
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.
| Name | Description | |
|---|---|---|
| StretchImage |
The original image will be squashed to fit into the target size. This may result in unattractive images and is not recommended. |
| 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. |
| 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.
|
| 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.
As the image may be cropped, it is not suitable for displaying
large, stand-alone images (you may consider ResizeMode.KeepOriginalRatio or
ResizeMode.KeepOriginalRatioByPadding instead).
|





