public abstract class Image extends DataStreamSupporter implements IObjectWithBounds
The image is the base class for all type of images.
DataStreamSupporter
,
IObjectWithBounds
Modifier and Type | Method and Description |
---|---|
static boolean |
canLoad(InputStream stream)
Determines whether image can be loaded from the specified stream.
|
static boolean |
canLoad(InputStream stream,
LoadOptions loadOptions)
Determines whether image can be loaded from the specified stream and optionally using the specified
loadOptions . |
static boolean |
canLoad(String filePath)
Determines whether image can be loaded from the specified file path.
|
static boolean |
canLoad(String filePath,
LoadOptions loadOptions)
Determines whether image can be loaded from the specified file path and optionally using the specified open options.
|
boolean |
canSave(ImageOptionsBase options)
Determines whether image can be saved to the specified file format represented by the passed save options.
|
static Image |
create(Image[] images)
Creates a new image using the specified images as pages
|
static Image |
create(Image[] images,
boolean disposeImages)
Creates a new image the specified images as pages.
|
static Image |
create(ImageOptionsBase imageOptions,
int width,
int height)
Creates a new image using the specified create options.
|
Color |
getBackgroundColor()
Gets or sets a value for the background color.
|
abstract int |
getBitsPerPixel()
Gets the image bits per pixel count.
|
Rectangle |
getBounds()
Gets the image bounds.
|
int |
getBufferSizeHint()
Gets the buffer size hint which is defined max allowed size for all internal buffers.
|
Image |
getContainer()
Gets the
Image container. |
ImageOptionsBase |
getDefaultOptions(Object[] args)
Gets the default options.
|
long |
getFileFormat()
Gets a value of file format
|
static long |
getFileFormat(InputStream stream)
Gets the file format.
|
static long |
getFileFormat(String filePath)
Gets the file format.
|
static Rectangle |
getFittingRectangle(Rectangle rectangle,
int[] pixels,
int width,
int height)
Gets rectangle which fits the current image.
|
static Rectangle |
getFittingRectangle(Rectangle rectangle,
int width,
int height)
Gets rectangle which fits the current image.
|
abstract int |
getHeight()
Gets the image height.
|
InterruptMonitor |
getInterruptMonitor()
Gets the interrupt monitor.
|
ImageOptionsBase |
getOriginalOptions()
Gets the options based on the original file settings.
|
IColorPalette |
getPalette()
Gets the color palette.
|
ProgressEventHandler |
getProgressEventHandler()
Gets the progress event handler information.
|
ProgressEventHandlerInfo |
getProgressEventHandlerInfo()
Gets the progress event handler information.
|
static int |
getProportionalHeight(int width,
int height,
int newWidth)
Gets a proportional height.
|
static int |
getProportionalWidth(int width,
int height,
int newHeight)
Gets a proportional width.
|
Size |
getSize()
Gets the image size.
|
abstract int |
getWidth()
Gets the image width.
|
boolean |
hasBackgroundColor()
Gets a value indicating whether image has background color.
|
boolean |
isAutoAdjustPalette()
Gets a value indicating whether automatic adjust palette.
|
boolean |
isUsePalette()
Gets a value indicating whether the image palette is used.
|
static Image |
load(InputStream stream)
Loads a new image from the specified stream.
|
static Image |
load(InputStream stream,
LoadOptions loadOptions)
Loads a new image from the specified stream.
|
static Image |
load(RandomAccessFile file)
Loads a new image from the specified stream.
|
static Image |
load(RandomAccessFile file,
LoadOptions loadOptions)
Loads a new image from the specified stream.
|
static Image |
load(String filePath)
Loads a new image from the specified file.
|
static Image |
load(String filePath,
LoadOptions loadOptions)
Loads a new image from the specified file.
|
void |
resize(int newWidth,
int newHeight)
Resizes the image.
|
abstract void |
resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Resizes the image.
|
abstract void |
resize(int newWidth,
int newHeight,
int resizeType)
Resizes the image.
|
void |
resizeHeightProportionally(int newHeight)
Resizes the height proportionally.
|
void |
resizeHeightProportionally(int newHeight,
ImageResizeSettings settings)
Resizes the height proportionally.
|
void |
resizeHeightProportionally(int newHeight,
int resizeType)
Resizes the height proportionally.
|
void |
resizeWidthProportionally(int newWidth)
Resizes the width proportionally.
|
void |
resizeWidthProportionally(int newWidth,
ImageResizeSettings settings)
Resizes the width proportionally.
|
void |
resizeWidthProportionally(int newWidth,
int resizeType)
Resizes the width proportionally.
|
abstract void |
rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
|
void |
save()
Saves the image data to the underlying stream.
|
void |
save(OutputStream stream,
ImageOptionsBase optionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
|
void |
save(OutputStream stream,
ImageOptionsBase optionsBase,
Rectangle boundsRectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
|
void |
save(RandomAccessFile file,
ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
|
void |
save(RandomAccessFile file,
ImageOptionsBase optionsBase,
Rectangle boundsRectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
|
void |
save(String filePath,
ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
|
void |
save(String filePath,
ImageOptionsBase options,
Rectangle boundsRectangle)
Saves the object's data to the specified file location in the specified file format according to save options.
|
void |
setAutoAdjustPalette(boolean value)
Sets a value indicating whether automatic adjust palette.
|
void |
setBackgroundColor(boolean value)
Gets or sets a value indicating whether image has background color.
|
void |
setBackgroundColor(Color value)
Gets or sets a value for the background color.
|
void |
setBufferSizeHint(int value)
Sets the buffer size hint which is defined max allowed size for all internal buffers.
|
void |
setInterruptMonitor(InterruptMonitor value)
Sets the interrupt monitor.
|
void |
setPalette(IColorPalette value)
Sets the color palette.
|
abstract void |
setPalette(IColorPalette palette,
boolean updateColors)
Sets the image palette.
|
cacheData, getDataStreamContainer, isCached, save, save, save, save, setDataStreamContainer
close, dispose, getDisposed
public static boolean canLoad(String filePath)
Determines whether image can be loaded from the specified file path.
filePath
- The file path.true
if image can be loaded from the specified file; otherwise, false
.public static boolean canLoad(String filePath, LoadOptions loadOptions)
Determines whether image can be loaded from the specified file path and optionally using the specified open options.
filePath
- The file path.loadOptions
- The load options.true
if image can be loaded from the specified file; otherwise, false
.public static boolean canLoad(InputStream stream)
Determines whether image can be loaded from the specified stream.
stream
- The stream to load from.true
if image can be loaded from the specified stream; otherwise, false
.public static boolean canLoad(InputStream stream, LoadOptions loadOptions)
Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions
.
stream
- The stream to load from.loadOptions
- The load options.true
if image can be loaded from the specified stream; otherwise, false
.public static Image create(ImageOptionsBase imageOptions, int width, int height)
Creates a new image using the specified create options.
imageOptions
- The image options.width
- The width.height
- The height.public static Image create(Image[] images)
Creates a new image using the specified images as pages
images
- The images.public static Image create(Image[] images, boolean disposeImages)
Creates a new image the specified images as pages.
images
- The images.disposeImages
- if set to true
[dispose images].public static long getFileFormat(String filePath)
Gets the file format.
filePath
- The file path.
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.
public static long getFileFormat(InputStream stream)
Gets the file format.
stream
- The stream.
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.
public static Rectangle getFittingRectangle(Rectangle rectangle, int width, int height)
Gets rectangle which fits the current image.
rectangle
- The rectangle to get fitting rectangle for.width
- The object width.height
- The object height.public static Rectangle getFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)
Gets rectangle which fits the current image.
rectangle
- The rectangle to get fitting rectangle for.pixels
- The 32-bit ARGB pixels.width
- The object width.height
- The object height.public static Image load(String filePath, LoadOptions loadOptions)
Loads a new image from the specified file.
filePath
- The file path to load image from.loadOptions
- The load options.public static Image load(String filePath)
Loads a new image from the specified file.
filePath
- The file path to load image from.public static Image load(RandomAccessFile file, LoadOptions loadOptions)
Loads a new image from the specified stream.
file
- The file to load image from.loadOptions
- The load options.public static Image load(RandomAccessFile file)
Loads a new image from the specified stream.
file
- The file to load image from.public static Image load(InputStream stream, LoadOptions loadOptions)
Loads a new image from the specified stream.
stream
- The stream to load image from.loadOptions
- The load options.public static Image load(InputStream stream)
Loads a new image from the specified stream.
stream
- The stream to load image from.public static int getProportionalWidth(int width, int height, int newHeight)
Gets a proportional width.
width
- The width.height
- The height.newHeight
- The new height.public static int getProportionalHeight(int width, int height, int newWidth)
Gets a proportional height.
width
- The width.height
- The height.newWidth
- The new width.public abstract int getBitsPerPixel()
Gets the image bits per pixel count.
public Rectangle getBounds()
Gets the image bounds.
getBounds
in interface IObjectWithBounds
public Image getContainer()
Gets the Image
container.
Image
container.
If this property is not null it indicates the image is contained whithin another image.
public abstract int getHeight()
Gets the image height.
getHeight
in interface IObjectWithBounds
public IColorPalette getPalette()
Gets the color palette. The color palette is not used when pixels are represented directly.
public void setPalette(IColorPalette value)
Sets the color palette. The color palette is not used when pixels are represented directly.
value
- The color palette.public boolean isUsePalette()
Gets a value indicating whether the image palette is used.
Value:true
if the palette is used in the image; otherwise, false
.public Size getSize()
Gets the image size.
getSize
in interface IObjectWithBounds
public abstract int getWidth()
Gets the image width.
getWidth
in interface IObjectWithBounds
public InterruptMonitor getInterruptMonitor()
Gets the interrupt monitor.
public void setInterruptMonitor(InterruptMonitor value)
Sets the interrupt monitor.
value
- the interrupt monitor.public final int getBufferSizeHint()
Gets the buffer size hint which is defined max allowed size for all internal buffers.
Value: The buffer size hint, in megabytes. Non-positive value means no memory limitation for internal bufferspublic final void setBufferSizeHint(int value)
Sets the buffer size hint which is defined max allowed size for all internal buffers.
Value: The buffer size hint, in megabytes. Non-positive value means no memory limitation for internal buffersvalue
- the buffer size hint which is defined max allowed size for all internal buffers.public boolean isAutoAdjustPalette()
Gets a value indicating whether automatic adjust palette.
true
if enable automatic adjust palette; otherwise, false
.public void setAutoAdjustPalette(boolean value)
Sets a value indicating whether automatic adjust palette.
value
- true
if enable automatic adjust palette; otherwise, false
.public boolean hasBackgroundColor()
Gets a value indicating whether image has background color.
public long getFileFormat()
Gets a value of file format
public Color getBackgroundColor()
Gets or sets a value for the background color.
public void setBackgroundColor(boolean value)
Gets or sets a value indicating whether image has background color.
public void setBackgroundColor(Color value)
Gets or sets a value for the background color.
public final ProgressEventHandler getProgressEventHandler()
Gets the progress event handler information.
public final ProgressEventHandlerInfo getProgressEventHandlerInfo()
Gets the progress event handler information.
Value: The progress event handler information.public boolean canSave(ImageOptionsBase options)
Determines whether image can be saved to the specified file format represented by the passed save options.
options
- The save options to use.true
if image can be saved to the specified file format represented by the passed save options; otherwise, false
.public void resize(int newWidth, int newHeight)
Resizes the image. The default ResizeType.LeftTopToLeftTop
is used.
newWidth
- The new width.newHeight
- The new height.public abstract void resize(int newWidth, int newHeight, int resizeType)
Resizes the image.
newWidth
- The new width.newHeight
- The new height.resizeType
- The resize type.public abstract void resize(int newWidth, int newHeight, ImageResizeSettings settings)
Resizes the image.
newWidth
- The new width.newHeight
- The new height.settings
- The resize settings.public ImageOptionsBase getDefaultOptions(Object[] args)
Gets the default options.
args
- The arguments.public ImageOptionsBase 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
DataStreamSupporter.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 Image.Save(string, ImageOptionsBase)
method as the second parameter.
public void resizeWidthProportionally(int newWidth)
Resizes the width proportionally.
newWidth
- The new width.public void resizeHeightProportionally(int newHeight)
Resizes the height proportionally.
newHeight
- The new height.public void resizeWidthProportionally(int newWidth, int resizeType)
Resizes the width proportionally.
newWidth
- The new width.resizeType
- Type of the resize.public void resizeHeightProportionally(int newHeight, int resizeType)
Resizes the height proportionally.
newHeight
- The new height.resizeType
- Type of the resize.public void resizeWidthProportionally(int newWidth, ImageResizeSettings settings)
Resizes the width proportionally.
newWidth
- The new width.settings
- The image resize settings.public void resizeHeightProportionally(int newHeight, ImageResizeSettings settings)
Resizes the height proportionally.
newHeight
- The new height.settings
- The image resize settings.public abstract void rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
rotateFlipType
- Type of the rotate flip.public final void save()
Saves the image data to the underlying stream.
save
in class DataStreamSupporter
public void save(String filePath, ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
filePath
- The file path.options
- The options.A base example of converting an AI file to the PDF file format. It just loads an existing AI file and explicitly saves one as a PDF file.
String inAiFilePath = "rect2_color.ai"; String outPdfFilePath = "rect2_color.ai_output.pdf"; // Load a regular AI file AiImage aiImage = (AiImage)Image.load(inAiFilePath); try { // Export the loaded AI file to the PDF file format with default options aiImage.save(outPdfFilePath, new PdfOptions()); } finally { aiImage.dispose(); }
public void save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
Saves the object's data to the specified file location in the specified file format according to save options.
filePath
- The file path.options
- The options.boundsRectangle
- The destination image bounds rectangle. Set the empty rectangle for use sourse bounds.com.aspose.ms.System.ArgumentNullException
- optionsImageSaveException
- Image saving failed.public void save(RandomAccessFile file, ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
file
- The file to save the image's data to.options
- The options.public void save(RandomAccessFile file, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
file
- The file to save the image's data to.optionsBase
- The save options.boundsRectangle
- The destination image bounds rectangle. Set the empty rectangle for use sourse bounds.com.aspose.ms.System.ArgumentNullException
- optionsBasecom.aspose.ms.System.ArgumentException
- Cannot save to the specified format as it is not supported at the moment.;optionsBaseImageSaveException
- Image export failed.public void save(OutputStream stream, ImageOptionsBase optionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
stream
- The stream to save the image's data to.optionsBase
- The save options.com.aspose.ms.System.ArgumentNullException
- optionsBasecom.aspose.ms.System.ArgumentException
- Cannot save to the specified format as it is not supported at the moment.;optionsBaseImageSaveException
- Image export failed.public void save(OutputStream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
stream
- The stream to save the image's data to.optionsBase
- The save options.boundsRectangle
- The destination image bounds rectangle. Set the empty rectangle for use source bounds.com.aspose.ms.System.ArgumentNullException
- optionsBasecom.aspose.ms.System.ArgumentException
- Cannot save to the specified format as it is not supported at the moment.;optionsBaseImageSaveException
- Image export failed.public abstract void setPalette(IColorPalette palette, boolean updateColors)
Sets the image palette.
palette
- The palette to set.updateColors
- 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.