Type ImageBuilder
Namespace ImageResizer
Parent AbstractImageProcessor
Interfaces IQuerystringPlugin, IFileExtensionPlugin
Provides methods for generating resized images, and for reading and writing them to disk.
Use ImageBuilder.Current to get the current instance (as configured in the application configuration), or use ImageBuilder.Current.Create() to control which extensions are used.
Methods
- Build
- Build
- Build
- Build
- Build
- Build
- Build
- Copy
- Create
- GetFinalSize
- GetFinalSize
- GetStreamFromSource
- LoadImage
- LoadImage
- LoadImageInfo
- Process
- TranslatePoints
Properties
Public instance methods
ImageJob Build(object source, object dest, Instructions instructions)
Resizes and processes the specified source image and stores the encoded result in the specified destination.
If passed a source Stream, Bitmap, or Image instance, it will be disposed after use. Use disposeSource=False to disable that behavior.
Parameters
-
object
source - May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. App-relative virtual paths will use the VirtualPathProvider system
-
object
dest - May be a physical path (string), or a Stream instance. Does not have to be seekable.
-
Instructions
instructions - Resizing and processing command to apply to the image.
void Build(object source, object dest, ResizeSettings settings, bool disposeSource)
Resizes and processes the specified source image and stores the encoded result in the specified destination.
If passed a source Stream, Bitmap, or Image instance, it will not be disposed unless disposeSource=true.
Parameters
-
object
source - May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. App-relative virtual paths will use the VirtualPathProvider system
-
object
dest - May be a physical path (string), or a Stream instance. Does not have to be seekable.
-
ResizeSettings
settings - Resizing and processing command to apply to the image.
-
bool
disposeSource - True to dispose 'source' after use. False to leave intact.
Bitmap Build(object source, ResizeSettings settings, bool disposeSource)
Resizes and processes the specified source image and returns a bitmap of the result.
Note!
This method assumes that transparency will be supported in the final output format, and therefore does not apply a matte color. Use &bgcolor to specify a background color
if you use this method with a non-transparent format such as Jpeg.
If passed a source Stream, Bitmap, or Image instance, it will not be disposed unless disposeSource=true.
Parameters
-
object
source - May be an instance of string (a physical path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream.
-
ResizeSettings
settings - Resizing and processing command to apply to the.
-
bool
disposeSource - If false, 'source' will not be disposed.
Bitmap Build(object source, ResizeSettings settings)
Resizes and processes the specified source image and returns a bitmap of the result.
Note!
This method assumes that transparency will be supported in the final output format, and therefore does not apply a matte color. Use &bgcolor to specify a background color
if you use this method with a non-transparent format such as Jpeg.
If passed a source Stream, Bitmap, or Image instance, it will be disposed after use. Use disposeSource=False to disable that behavior.
Parameters
-
object
source - May be an instance of string (a physical path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream.
-
ResizeSettings
settings - Resizing and processing command to apply to the.
void Build(object source, object dest, ResizeSettings settings)
Resizes and processes the specified source image and stores the encoded result in the specified destination.
If passed a source Stream, Bitmap, or Image instance, it will be disposed after use. Use disposeSource=False to disable that behavior.
Parameters
-
object
source - May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. App-relative virtual paths will use the VirtualPathProvider system
-
object
dest - May be a physical path (string), or a Stream instance. Does not have to be seekable.
-
ResizeSettings
settings - Resizing and processing command to apply to the image.
string Build(object source, object dest, ResizeSettings settings, bool disposeSource, bool addFileExtension)
Resizes and processes the specified source image and stores the encoded result in the specified destination.
If passed a source Stream, Bitmap, or Image instance, it will not be disposed unless disposeSource=true.
If passed a path destination, the physical path of the written file will be returned.
Parameters
-
object
source - May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. App-relative virtual paths will use the VirtualPathProvider system
-
object
dest - May be a physical path (string), or a Stream instance. Does not have to be seekable.
-
ResizeSettings
settings - Resizing and processing command to apply to the image.
-
bool
disposeSource - True to dispose 'source' after use. False to leave intact.
-
bool
addFileExtension - If true, will add the correct file extension to 'dest' if it is a string.
ImageBuilder Copy()
Copies the instance along with extensions. Subclasses must override this.
ImageBuilder Create(IEnumerable<BuilderExtension> extensions, IEncoderProvider writer, IVirtualImageProvider virtualFileProvider, ISettingsModifier settingsModifier)
Creates another instance of the class using the specified extensions. Subclasses should override this and point to their own constructor.
Size GetFinalSize(Size originalSize, ResizeSettings q)
Gets the final size of an image
Size GetFinalSize(Size originalSize, Instructions q)
Gets the final size of an image
Stream GetStreamFromSource(object source, ResizeSettings settings, Boolean& disposeStream, String& path, Boolean& restoreStreamPosition)
Bitmap LoadImage(object source, ResizeSettings settings, bool restoreStreamPos)
Loads a Bitmap from the specified source. If a filename is available, it will be attached to bitmap.Tag in a BitmapTag instance. The Bitmap.Tag.Path value may be a virtual, relative, UNC, windows, or unix path.
Does not dispose 'source' if it is a Stream or Image instance - that's the responsibility of the calling code.
Parameters
-
object
source - May be an instance of string, VirtualFile, IVirtualFile IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. If passed an Image instance, the image will be cloned, which will cause metadata, indexed state, and any additional frames to be lost. Accepts physical paths and application relative paths. (C:\... and ~/path)
-
ResizeSettings
settings - Will ignore ICC profile if ?ignoreicc=true.
-
bool
restoreStreamPos - If true, the position of the source stream will be restored after being read
Returns
-
Bitmap
- A Bitmap. The.Tag property will include a BitmapTag instance. If.Tag.Source is not null, remember to dispose it when you dispose the Bitmap.
Bitmap LoadImage(object source, ResizeSettings settings)
Loads a Bitmap from the specified source. If a filename is available, it will be attached to bitmap.Tag in a BitmapTag instance. The Bitmap.Tag.Path value may be a virtual, relative, UNC, windows, or unix path.
Does not dispose 'source' if it is a Stream or Image instance - that's the responsibility of the calling code.
Parameters
-
object
source - May be an instance of string, VirtualFile, IVirtualFile IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. If passed an Image instance, the image will be cloned, which will cause metadata, indexed state, and any additional frames to be lost. Accepts physical paths and application relative paths. (C:\... and ~/path)
-
ResizeSettings
settings - Will ignore ICC profile if ?ignoreicc=true.
Returns
-
Bitmap
- A Bitmap. The.Tag property will include a BitmapTag instance. If.Tag.Source is not null, remember to dispose it when you dispose the Bitmap.
IDictionary<string, object> LoadImageInfo(object source, IEnumerable<string> requestedInfo)
Returns a dictionary of information about the given image.
Parameters
-
object
source -
IEnumerable<string>
requestedInfo - Pass null to get the defaults ("source.width", source.height")
void Process(ImageState s)
Processes an ImageState instance. Used by Build, GetFinalSize, and TranslatePoint.
Can be overriden by a plugin with the OnProcess method
PointF[] TranslatePoints(PointF[] sourcePoints, Size originalSize, ResizeSettings q)
Doesn't support flipping. Translate a point on the original bitmap to a point on the new bitmap. If the original point no longer exists, returns Empty
Public properties
ImageBuilder Current get;
Returns a shared instance of ImageBuilder or a subclass, equivalent to Config.Current.CurrentImageBuilder
IEncoderProvider EncoderProvider get;
Handles the encoder selection and provision proccess.
ISettingsModifier SettingsModifier get;
May be null. A class to modify or normalize ResizeSettings instances before they are used.
IVirtualImageProvider VirtualFileProvider get;
Provides a resolution service for app-relative URLs.