Table of Contents

Class Image

Namespace
Aspose.Imaging
Assembly
Aspose.Imaging.dll

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 IColorPalette

The 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

Color
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

Image

The Image container.

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

FileFormat
See Also

HasBackgroundColor

Gets or sets a value indicating whether image has background color.

public virtual bool HasBackgroundColor { get; set; }

Property Value

bool
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

InterruptMonitor
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 Stream

The 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 Stream

The stream to load from.

loadOptions LoadOptions

The 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 string

The 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 string

The file path.

loadOptions LoadOptions

The 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 ImageOptionsBase

The 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 ImageOptionsBase

The image options.

width int

The width.

height int

The 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

images Image[]

The images.

disposeImages bool

if set to true [dispose images].

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 ImageOptionsBase

The 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 Stream

The 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 string

The 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 Rectangle

The 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 Rectangle

The 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 Rectangle

The rectangle to get fitting rectangle for.

width int

The object width.

height int

The 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 Rectangle

The rectangle to get fitting rectangle for.

pixels int[]

The 32-bit ARGB pixels.

width int

The object width.

height int

The 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 ImageOptionsBase

The image options base.

boundsRectangle Rectangle

The bounds rectangle.

exporter IImageExporter

The 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

width int

The width.

height int

The height.

newWidth int

The new width.

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

width int

The width.

height int

The height.

newHeight int

The new height.

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 ImageOptionsBase

The image options.

clippingRectangle Rectangle

The clipping rectangle.

pageNumber int

The 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 Stream

The 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 Stream

The stream to load image from.

loadOptions LoadOptions

The 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 string

The 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 string

The file path to load image from.

loadOptions LoadOptions

The 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 IColorPalette

The old palette.

newPalette IColorPalette

The new palette.

See Also

OnPaletteChanging(IColorPalette, IColorPalette)

Called when palette is changing.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

The old palette.

newPalette IColorPalette

The 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

newWidth int

The new width.

newHeight int

The new height.

See Also

Resize(int, int, ImageResizeSettings)

Resizes the image.

public abstract void Resize(int newWidth, int newHeight, ImageResizeSettings settings)

Parameters

newWidth int

The new width.

newHeight int

The new height.

settings ImageResizeSettings

The resize settings.

See Also

Resize(int, int, ResizeType)

Resizes the image.

public abstract void Resize(int newWidth, int newHeight, ResizeType resizeType)

Parameters

newWidth int

The new width.

newHeight int

The new height.

resizeType ResizeType

The resize type.

See Also

ResizeHeightProportionally(int)

Resizes the height proportionally. The default NearestNeighbourResample is used.

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

The new height.

See Also

ResizeHeightProportionally(int, ImageResizeSettings)

Resizes the height proportionally.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

The new height.

settings ImageResizeSettings

The image resize settings.

See Also

ResizeHeightProportionally(int, ResizeType)

Resizes the height proportionally.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

The new height.

resizeType ResizeType

Type of the resize.

See Also

ResizeWidthProportionally(int)

Resizes the width proportionally. The default NearestNeighbourResample is used.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

The new width.

See Also

ResizeWidthProportionally(int, ImageResizeSettings)

Resizes the width proportionally.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

The new width.

settings ImageResizeSettings

The image resize settings.

See Also

ResizeWidthProportionally(int, ResizeType)

Resizes the width proportionally.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

The new width.

resizeType ResizeType

Type of the resize.

See Also

RotateFlip(RotateFlipType)

Rotates, flips, or rotates and flips the image.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

Type 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 Stream

The stream to save the image's data to.

optionsBase ImageOptionsBase

The 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 Stream

The stream to save the image's data to.

optionsBase ImageOptionsBase

The save options.

boundsRectangle Rectangle

The 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 string

The 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 string

The file path.

options ImageOptionsBase

The 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 string

The file path.

options ImageOptionsBase

The options.

boundsRectangle Rectangle

The 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 IColorPalette

The palette to set.

updateColors bool

if 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 Image

The container.

See Also

See Also