Class Image
The image is the base class for all type of images.
public abstract class Image : DataStreamSupporter, IDisposable, IObjectWithBounds
- Inheritance
-
Image
- Implements
- Derived
- Inherited Members
Constructors
Image()
Initializes a new instance of the Image class.
protected Image()
- See Also
Image(IColorPalette)
Initializes a new instance of the Image class.
protected Image(IColorPalette colorPalette)
Parameters
colorPalette
IColorPaletteThe color palette.
- See Also
Properties
AutoAdjustPalette
Gets or sets a value indicating whether automatic adjust palette.
public bool AutoAdjustPalette { get; set; }
Property Value
- bool
true
if enable automatic adjust palette; otherwise,false
.
- See Also
BackgroundColor
Gets or sets a value for the background color.
public virtual Color BackgroundColor { get; set; }
Property Value
- See Also
BitsPerPixel
Gets the image bits per pixel count.
public abstract int BitsPerPixel { get; }
Property Value
- int
The image bits per pixel count.
- See Also
Bounds
Gets the image bounds.
public Rectangle Bounds { get; }
Property Value
- Rectangle
The image bounds.
- See Also
BufferSizeHint
Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
public int BufferSizeHint { get; set; }
Property Value
- int
The buffer size hint, in megabytes. Non-positive value means no memory limitation for internal buffers
- See Also
Container
Gets the Image container.
public Image Container { get; }
Property Value
Remarks
If this property is not null it indicates the image is contained within another image.
- See Also
FileFormat
Gets a value of file format
public virtual FileFormat FileFormat { get; }
Property Value
- See Also
HasBackgroundColor
Gets or sets a value indicating whether image has background color.
public virtual bool HasBackgroundColor { get; set; }
Property Value
- See Also
Height
Gets the image height.
public abstract int Height { get; }
Property Value
- int
The image height.
- See Also
InterruptMonitor
Gets or sets the interrupt monitor.
public InterruptMonitor InterruptMonitor { get; set; }
Property Value
- See Also
Palette
Gets or sets the color palette. The color palette is not used when pixels are represented directly.
public IColorPalette Palette { get; set; }
Property Value
- IColorPalette
The color palette.
- See Also
Size
Gets the image size.
public Size Size { get; }
Property Value
- Size
The image size.
- See Also
UsePalette
Gets a value indicating whether the image palette is used.
public virtual bool UsePalette { get; }
Property Value
- bool
true
if the palette is used in the image; otherwise,false
.
- See Also
Width
Gets the image width.
public abstract int Width { get; }
Property Value
- int
The image width.
- See Also
Methods
CanLoad(Stream)
Determines whether image can be loaded from the specified stream.
public static bool CanLoad(Stream stream)
Parameters
stream
StreamThe stream to load from.
Returns
- bool
true
if image can be loaded from the specified stream; otherwise,false
.
- See Also
CanLoad(Stream, LoadOptions)
Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions
.
public static bool CanLoad(Stream stream, LoadOptions loadOptions)
Parameters
stream
StreamThe stream to load from.
loadOptions
LoadOptionsThe load options.
Returns
- bool
true
if image can be loaded from the specified stream; otherwise,false
.
- See Also
CanLoad(string)
Determines whether image can be loaded from the specified file path.
public static bool CanLoad(string filePath)
Parameters
filePath
stringThe file path.
Returns
- bool
true
if image can be loaded from the specified file; otherwise,false
.
- See Also
CanLoad(string, LoadOptions)
Determines whether image can be loaded from the specified file path and optionally using the specified open options.
public static bool CanLoad(string filePath, LoadOptions loadOptions)
Parameters
filePath
stringThe file path.
loadOptions
LoadOptionsThe load options.
Returns
- bool
true
if image can be loaded from the specified file; otherwise,false
.
- See Also
CanSave(ImageOptionsBase)
Determines whether image can be saved to the specified file format represented by the passed save options.
public bool CanSave(ImageOptionsBase options)
Parameters
options
ImageOptionsBaseThe save options to use.
Returns
- bool
true
if image can be saved to the specified file format represented by the passed save options; otherwise,false
.
- See Also
Create(ImageOptionsBase, int, int)
Creates a new image using the specified create options.
public static Image Create(ImageOptionsBase imageOptions, int width, int height)
Parameters
imageOptions
ImageOptionsBaseThe image options.
width
intThe width.
height
intThe height.
Returns
- Image
The newly created image.
- See Also
Create(Image[])
Creates a new image using the specified images as pages
public static Image Create(Image[] images)
Parameters
images
Image[]The images.
Returns
- Image
The Image as IMultipageImage
- See Also
Create(Image[], bool)
Creates a new image the specified images as pages.
public static Image Create(Image[] images, bool disposeImages)
Parameters
Returns
- Image
The Image as IMultipageImage
- See Also
~Image()
protected ~Image()
- See Also
GetCanNotSaveMessage(ImageOptionsBase)
Gets the can not save message.
protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)
Parameters
optionsBase
ImageOptionsBaseThe image options.
Returns
- string
The can not save message.
- See Also
GetDefaultOptions(object[])
Gets the default options.
public virtual ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object[]The arguments.
Returns
- ImageOptionsBase
Default options
- See Also
GetFileFormat(Stream)
Gets the file format.
public static FileFormat GetFileFormat(Stream stream)
Parameters
stream
StreamThe stream.
Returns
- FileFormat
The determined file format.
Remarks
The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether stream may be loaded.
- See Also
GetFileFormat(string)
Gets the file format.
public static FileFormat GetFileFormat(string filePath)
Parameters
filePath
stringThe file path.
Returns
- FileFormat
The determined file format.
Remarks
The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether file may be loaded.
- See Also
GetFitRectangle(Rectangle)
Gets rectangle which fits the current image.
protected Rectangle GetFitRectangle(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to get fitting rectangle for.
Returns
- Rectangle
The fitting rectangle
- See Also
GetFitRectangle(Rectangle, int[])
Gets rectangle which fits the current bitmap taking into account the pixels passed. The passed pixels array count should be equal to the fitting rectangle size.
protected Rectangle GetFitRectangle(Rectangle rectangle, int[] pixels)
Parameters
rectangle
RectangleThe rectangle to get fitting rectangle for.
pixels
int[]The 32-bit ARGB pixels array.
Returns
- Rectangle
The fitting rectangle.
- See Also
GetFittingRectangle(Rectangle, int, int)
Gets rectangle which fits the current image.
public static Rectangle GetFittingRectangle(Rectangle rectangle, int width, int height)
Parameters
rectangle
RectangleThe rectangle to get fitting rectangle for.
width
intThe object width.
height
intThe object height.
Returns
- Rectangle
The fitting rectangle or exception if no fitting rectangle can be found.
- See Also
GetFittingRectangle(Rectangle, int[], int, int)
Gets rectangle which fits the current image.
public static Rectangle GetFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)
Parameters
rectangle
RectangleThe rectangle to get fitting rectangle for.
pixels
int[]The 32-bit ARGB pixels.
width
intThe object width.
height
intThe object height.
Returns
- Rectangle
The fitting rectangle or exception if no fitting rectangle can be found.
- See Also
GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter)
Gets the image to export.
[Obsolete("Will be changed by method with other signature")]
protected virtual Image GetImage2Export(ImageOptionsBase optionsBase, Rectangle boundsRectangle, IImageExporter exporter)
Parameters
optionsBase
ImageOptionsBaseThe image options base.
boundsRectangle
RectangleThe bounds rectangle.
exporter
IImageExporterThe exporter.
Returns
- Image
The image to export
- See Also
GetOriginalOptions()
Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save(string) method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save(string, ImageOptionsBase) method as the second parameter.
public virtual ImageOptionsBase GetOriginalOptions()
Returns
- ImageOptionsBase
The options based on the original file settings.
- See Also
GetProportionalHeight(int, int, int)
Gets a proportional height.
public static int GetProportionalHeight(int width, int height, int newWidth)
Parameters
Returns
- int
The proportional height.
- See Also
GetProportionalWidth(int, int, int)
Gets a proportional width.
public static int GetProportionalWidth(int width, int height, int newHeight)
Parameters
Returns
- int
The proportional width.
- See Also
GetSerializedStream(ImageOptionsBase, Rectangle, out int)
Converts to aps.
public virtual Stream GetSerializedStream(ImageOptionsBase imageOptions, Rectangle clippingRectangle, out int pageNumber)
Parameters
imageOptions
ImageOptionsBaseThe image options.
clippingRectangle
RectangleThe clipping rectangle.
pageNumber
intThe page number.
Returns
- Stream
The serialized stream
- See Also
Load(Stream)
Loads a new image from the specified stream.
public static Image Load(Stream stream)
Parameters
stream
StreamThe stream to load image from.
Returns
- Image
The loaded image.
- See Also
Load(Stream, LoadOptions)
Loads a new image from the specified stream.
public static Image Load(Stream stream, LoadOptions loadOptions)
Parameters
stream
StreamThe stream to load image from.
loadOptions
LoadOptionsThe load options.
Returns
- Image
The loaded image.
- See Also
Load(string)
Loads a new image from the specified file.
public static Image Load(string filePath)
Parameters
filePath
stringThe file path to load image from.
Returns
- Image
The loaded image.
- See Also
Load(string, LoadOptions)
Loads a new image from the specified file.
public static Image Load(string filePath, LoadOptions loadOptions)
Parameters
filePath
stringThe file path to load image from.
loadOptions
LoadOptionsThe load options.
Returns
- Image
The loaded image.
- See Also
OnPaletteChanged(IColorPalette, IColorPalette)
Called when palette is changed.
protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPaletteThe old palette.
newPalette
IColorPaletteThe new palette.
- See Also
OnPaletteChanging(IColorPalette, IColorPalette)
Called when palette is changing.
protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPaletteThe old palette.
newPalette
IColorPaletteThe new palette.
- See Also
ReleaseManagedResources()
Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.
protected override void ReleaseManagedResources()
- See Also
RemoveMetadata()
Removes metadata.
public virtual void RemoveMetadata()
- See Also
Resize(int, int)
Resizes the image. The default NearestNeighbourResample is used.
public void Resize(int newWidth, int newHeight)
Parameters
- See Also
Resize(int, int, ImageResizeSettings)
Resizes the image.
public abstract void Resize(int newWidth, int newHeight, ImageResizeSettings settings)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
settings
ImageResizeSettingsThe resize settings.
- See Also
Resize(int, int, ResizeType)
Resizes the image.
public abstract void Resize(int newWidth, int newHeight, ResizeType resizeType)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
resizeType
ResizeTypeThe resize type.
- See Also
ResizeHeightProportionally(int)
Resizes the height proportionally. The default NearestNeighbourResample is used.
public void ResizeHeightProportionally(int newHeight)
Parameters
newHeight
intThe new height.
- See Also
ResizeHeightProportionally(int, ImageResizeSettings)
Resizes the height proportionally.
public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)
Parameters
newHeight
intThe new height.
settings
ImageResizeSettingsThe image resize settings.
- See Also
ResizeHeightProportionally(int, ResizeType)
Resizes the height proportionally.
public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)
Parameters
newHeight
intThe new height.
resizeType
ResizeTypeType of the resize.
- See Also
ResizeWidthProportionally(int)
Resizes the width proportionally. The default NearestNeighbourResample is used.
public void ResizeWidthProportionally(int newWidth)
Parameters
newWidth
intThe new width.
- See Also
ResizeWidthProportionally(int, ImageResizeSettings)
Resizes the width proportionally.
public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)
Parameters
newWidth
intThe new width.
settings
ImageResizeSettingsThe image resize settings.
- See Also
ResizeWidthProportionally(int, ResizeType)
Resizes the width proportionally.
public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)
Parameters
newWidth
intThe new width.
resizeType
ResizeTypeType of the resize.
- See Also
RotateFlip(RotateFlipType)
Rotates, flips, or rotates and flips the image.
public abstract void RotateFlip(RotateFlipType rotateFlipType)
Parameters
rotateFlipType
RotateFlipTypeType of the rotate flip.
- See Also
Save()
Saves the image data to the underlying stream.
public override sealed void Save()
- See Also
Save(Stream, ImageOptionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
public void Save(Stream stream, ImageOptionsBase optionsBase)
Parameters
stream
StreamThe stream to save the image's data to.
optionsBase
ImageOptionsBaseThe save options.
Exceptions
- ArgumentNullException
optionsBase
- ArgumentException
Cannot save to the specified format as it is not supported at the moment.;optionsBase
- ImageSaveException
Image export failed.
- See Also
Save(Stream, ImageOptionsBase, Rectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
public virtual void Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Parameters
stream
StreamThe stream to save the image's data to.
optionsBase
ImageOptionsBaseThe save options.
boundsRectangle
RectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.
Exceptions
- ArgumentNullException
optionsBase
- ArgumentException
Cannot save to the specified format as it is not supported at the moment.;optionsBase
- ImageSaveException
Image export failed.
- See Also
Save(string)
Saves the image to the specified file location.
public override void Save(string filePath)
Parameters
filePath
stringThe file path to save the image to.
- See Also
Save(string, ImageOptionsBase)
Saves the object's data to the specified file location in the specified file format according to save options.
public virtual void Save(string filePath, ImageOptionsBase options)
Parameters
filePath
stringThe file path.
options
ImageOptionsBaseThe options.
- See Also
Save(string, ImageOptionsBase, Rectangle)
Saves the object's data to the specified file location in the specified file format according to save options.
public virtual void Save(string filePath, ImageOptionsBase options, Rectangle boundsRectangle)
Parameters
filePath
stringThe file path.
options
ImageOptionsBaseThe options.
boundsRectangle
RectangleThe destination image bounds rectangle. Set the empty rectangle for use sourse bounds.
Exceptions
- ArgumentNullException
options
- ImageSaveException
Image saving failed.
- See Also
SetPalette(IColorPalette, bool)
Sets the image palette.
public abstract void SetPalette(IColorPalette palette, bool updateColors)
Parameters
palette
IColorPaletteThe palette to set.
updateColors
boolif set to
true
colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.
- See Also
UpdateContainer(Image)
Updates the container.
protected void UpdateContainer(Image container)
Parameters
container
ImageThe container.
- See Also