Image

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter

All Implemented Interfaces: com.aspose.imaging.IObjectWithBounds, com.aspose.internal.progressmanagement.IProgressInformer, com.aspose.internal.progressmanagement.IProgressEventHandler

public abstract class Image extends DataStreamSupporter implements IObjectWithBounds, IProgressInformer, IProgressEventHandler

The image is the base class for all type of images.

Methods

MethodDescription
canLoad(String filePath)Determines whether image can be loaded from the specified file path.
canLoad(String filePath, LoadOptions loadOptions)Determines whether image can be loaded from the specified file path and optionally using the specified open options.
canLoad(InputStream stream)Determines whether image can be loaded from the specified stream.
canLoad(InputStream stream, LoadOptions loadOptions)Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.
create(ImageOptionsBase imageOptions, int width, int height)Creates a new image using the specified create options.
create(Image[] images)Creates a new image using the specified images as pages
create(MultipageCreateOptions multipageCreateOptions)Creates the specified multipage create options.
create(String[] files, boolean throwExceptionOnLoadError)Creates the specified files.
create(String[] files)Creates the specified files.
create(Image[] images, boolean disposeImages)Creates a new image the specified images as pages.
getFileFormat(String filePath)Gets the file format.
load(String filePath, LoadOptions loadOptions)Loads a new image from the specified file path or URL.
load(String filePath)Loads a new image from the specified file path or URL.
load(RandomAccessFile file, LoadOptions loadOptions)Loads a new image from the specified stream.
load(RandomAccessFile file)Loads a new image from the specified stream.
load(InputStream stream, LoadOptions loadOptions)Loads a new image from the specified stream.
load(InputStream stream)Loads a new image from the specified stream.
getFileFormat(InputStream stream)Gets the file format.
getFittingRectangle(Rectangle rectangle, int width, int height)Gets rectangle which fits the current image.
getFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)Gets rectangle which fits the current image.
getProportionalWidth(int width, int height, int newHeight)Gets a proportional width.
getProportionalHeight(int width, int height, int newWidth)Gets a proportional height.
removeMetadata()Removes metadata.
getBitsPerPixel()Gets the image bits per pixel count.
getBounds()Gets the image bounds.
getContainer()Gets the Image container.
getHeight()Gets the image height.
getPalette()Gets the color palette.
setPalette(IColorPalette value)Sets the color palette.
isUsePalette()Gets a value indicating whether the image palette is used.
getSize()Gets the image size.
getWidth()Gets the image width.
getInterruptMonitor()Gets the interrupt monitor.
setInterruptMonitor(InterruptMonitor value)Sets the interrupt monitor.
getBufferSizeHint()Gets the buffer size hint which is defined max allowed size for all internal buffers.
setBufferSizeHint(int value)Sets the buffer size hint which is defined max allowed size for all internal buffers.
isAutoAdjustPalette()Gets a value indicating whether automatic adjust palette.
setAutoAdjustPalette(boolean value)Sets a value indicating whether automatic adjust palette.
hasBackgroundColor()Gets a value indicating whether image has background color.
getFileFormat()Easily retrieve the file format value with this user-friendly property.
getBackgroundColor()Gets or sets a value for the background color.
setBackgroundColor(boolean value)Gets or sets a value indicating whether image has background color.
setBackgroundColor(Color value)Gets or sets a value for the background color.
getIProgressEventHandler()Gets the progress event handler information.
getProgressEventHandlerInfo()Gets the progress event handler information.
canSave(ImageOptionsBase options)Determines whether image can be saved to the specified file format represented by the passed save options.
resize(int newWidth, int newHeight)Resizes the image.
resize(int newWidth, int newHeight, int resizeType)Resizes the image.
resize(int newWidth, int newHeight, ImageResizeSettings settings)Resizes the image.
getDefaultOptions(Object[] args)Gets the default options.
getOriginalOptions()Gets the options based on the original file settings.
resizeWidthProportionally(int newWidth)Resizes the width proportionally.
resizeHeightProportionally(int newHeight)Resizes the height proportionally.
resizeWidthProportionally(int newWidth, int resizeType)Resizes the width proportionally.
resizeHeightProportionally(int newHeight, int resizeType)Resizes the height proportionally.
resizeWidthProportionally(int newWidth, ImageResizeSettings settings)Resizes the width proportionally.
resizeHeightProportionally(int newHeight, ImageResizeSettings settings)Resizes the height proportionally.
rotateFlip(int rotateFlipType)Rotates, flips, or rotates and flips the image.
save()Saves the image data to the underlying stream.
save(String filePath)Saves the image to the specified file location.
save(String filePath, ImageOptionsBase options)Saves the object’s data to the specified file location in the specified file format according to save options.
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.
save(RandomAccessFile file, ImageOptionsBase options)Saves the object’s data to the specified file location in the specified file format according to save options.
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.
save(OutputStream stream, ImageOptionsBase optionsBase)Saves the image’s data to the specified stream in the specified file format according to save options.
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.
setPalette(IColorPalette palette, boolean updateColors)Sets the image palette.
getSerializedStream(ImageOptionsBase imageOptions, Rectangle clippingRectangle, int[] pageNumber)Converts to aps.

Example: This example creates a new Image file at some disk location as specified by Source property of the BmpOptions instance.

This example creates a new Image file at some disk location as specified by Source property of the BmpOptions instance. Several properties for BmpOptions instance are set before creating the actual image. Especially the Source property, that refers to the actual disk location in this case.

// Create an instance of BmpOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpOptions.setBitsPerPixel(24);

// Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
// Second Boolean parameter determines if the file to be created IsTemporal or not
bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));

// Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
try {
    // Do some image processing

    // Save all changes
    image.save();
} finally {
    image.dispose();
}

Example: Resize image using specific Resize Type.

try (Image image = Image.load("Photo.jpg"))
{
    image.resize(640, 480, ResizeType.CatmullRom);
    image.save("ResizedPhoto.jpg");

    image.resize(1024, 768, ResizeType.CubicConvolution);
    image.save("ResizedPhoto2.jpg");

    ImageResizeSettings resizeSettings = new ImageResizeSettings();
    resizeSettings.setMode(ResizeType.CubicBSpline);
    resizeSettings.setFilterType(ImageFilterType.SmallRectangular);

    image.resize(800, 800, resizeSettings);
    image.save("ResizedPhoto3.jpg");
}

Example: Determine if the palette is used by the image.

try (Image image = Image.load("Sample.bmp"))
{
    if (image.isUsePalette())
    {
        System.out.println("The palette is used by the image");
    }
}

canLoad(String filePath)

public static boolean canLoad(String filePath)

Determines whether image can be loaded from the specified file path.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path.

Returns: boolean - true if image can be loaded from the specified file; otherwise, false.

Example: This example determines whether image can be loaded from a file.


// Use an absolute path to the file
boolean canLoad = com.aspose.imaging.Image.canLoad("c:\\temp\\sample.gif");

canLoad(String filePath, LoadOptions loadOptions)

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.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path.
loadOptionsLoadOptionsThe load options.

Returns: boolean - true if image can be loaded from the specified file; otherwise, false.

canLoad(InputStream stream)

public static boolean canLoad(InputStream stream)

Determines whether image can be loaded from the specified stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to load from.

Returns: boolean - true if image can be loaded from the specified stream; otherwise, false.

Example: This example determines whether image can be loaded from a file stream.

String dir = "c:\\temp\\";

boolean canLoad;

// Use a file stream
java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.bmp");
try {
    canLoad = com.aspose.imaging.Image.canLoad(stream);
} finally {
    stream.close();
}

// The following data is not a valid image stream, so CanLoad returns false.
byte[] imageData = new byte[]{0, 0, 0, 0, 0, 0, 0, 0};
stream = new java.io.ByteArrayInputStream(imageData);
{
    canLoad = com.aspose.imaging.Image.canLoad(stream);
}

canLoad(InputStream stream, LoadOptions loadOptions)

public static boolean canLoad(InputStream stream, LoadOptions loadOptions)

Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to load from.
loadOptionsLoadOptionsThe load options.

Returns: boolean - true if image can be loaded from the specified stream; otherwise, false.

create(ImageOptionsBase imageOptions, int width, int height)

public static Image create(ImageOptionsBase imageOptions, int width, int height)

Creates a new image using the specified create options.

Parameters:

ParameterTypeDescription
imageOptionsImageOptionsBaseThe image options.
widthintThe width.
heightintThe height.

Returns: Image - The newly created image.

Example: This example creates a new Image file at some disk location as specified by Source property of the BmpOptions instance. This example creates a new Image file at some disk location as specified by Source property of the BmpOptions instance. Several properties for BmpOptions instance are set before creating the actual image. Especially the Source property, that refers to the actual disk location in this case.

// Create an instance of BmpOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpOptions.setBitsPerPixel(24);

// Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
// Second Boolean parameter determines if the file to be created IsTemporal or not
bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));

// Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
try {
    // Do some image processing

    // Save all changes
    image.save();
} finally {
    image.dispose();
}

create(Image[] images)

public static Image create(Image[] images)

Creates a new image using the specified images as pages

Parameters:

ParameterTypeDescription
imagesImage[]The images.

Returns: Image - The Image as IMultipageImage

create(MultipageCreateOptions multipageCreateOptions)

public static Image create(MultipageCreateOptions multipageCreateOptions)

Creates the specified multipage create options.

Parameters:

ParameterTypeDescription
multipageCreateOptionsMultipageCreateOptionsThe multipage create options.

Returns: Image - The multipage image

create(String[] files, boolean throwExceptionOnLoadError)

public static Image create(String[] files, boolean throwExceptionOnLoadError)

Creates the specified files.

Parameters:

ParameterTypeDescription
filesjava.lang.String[]The files.
throwExceptionOnLoadErrorbooleanif set to true [throw exception on load error].

Returns: Image - The multipage image

create(String[] files)

public static Image create(String[] files)

Creates the specified files.

Parameters:

ParameterTypeDescription
filesjava.lang.String[]The files.

Returns: Image - The multipage image

create(Image[] images, boolean disposeImages)

public static Image create(Image[] images, boolean disposeImages)

Creates a new image the specified images as pages.

Parameters:

ParameterTypeDescription
imagesImage[]The images.
disposeImagesbooleanif set to true [dispose images].

Returns: Image - The Image as IMultipageImage

getFileFormat(String filePath)

public static long getFileFormat(String filePath)

Gets the file format.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe 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. |

Returns: long - The determined file format.

Example: This example shows how to determine the image format without loading the entire image from a file.

String dir = "c:\\temp\\";

// Use an absolute path to the file
long format = com.aspose.imaging.Image.getFileFormat(dir + "sample.gif");

// A string represenation of the file format.
String strFormat;
if (format == com.aspose.imaging.FileFormat.Bmp) {
    strFormat = "BMP";
} else if (format == com.aspose.imaging.FileFormat.Gif) {
    strFormat = "GIF";
} else if (format == com.aspose.imaging.FileFormat.Dicom) {
    strFormat = "DICOM";
} else if (format == com.aspose.imaging.FileFormat.Djvu) {
    strFormat = "DJVU";
} else if (format == com.aspose.imaging.FileFormat.Dng) {
    strFormat = "DNG";
} else if (format == com.aspose.imaging.FileFormat.Png) {
    strFormat = "PNG";
} else if (format == com.aspose.imaging.FileFormat.Jpeg) {
    strFormat = "JPEG";
} else if (format == com.aspose.imaging.FileFormat.Jpeg2000) {
    strFormat = "JPEG2000";
} else if (format == com.aspose.imaging.FileFormat.Psd) {
    strFormat = "PSD";
} else if (format == com.aspose.imaging.FileFormat.Tiff) {
    strFormat = "Tiff";
} else if (format == com.aspose.imaging.FileFormat.Webp) {
    strFormat = "WEBP";
} else if (format == com.aspose.imaging.FileFormat.Cdr) {
    strFormat = "CDR";
} else if (format == com.aspose.imaging.FileFormat.Cmx) {
    strFormat = "CMX";
} else if (format == com.aspose.imaging.FileFormat.Emf) {
    strFormat = "EMF";
} else if (format == com.aspose.imaging.FileFormat.Wmf) {
    strFormat = "WMF";
} else if (format == com.aspose.imaging.FileFormat.Svg) {
    strFormat = "SVG";
} else if (format == com.aspose.imaging.FileFormat.Odg) {
    strFormat = "ODG";
} else if (format == com.aspose.imaging.FileFormat.Eps) {
    strFormat = "EPS";
} else {
    strFormat = "UNDEFINED";
}

System.out.println("The file format is " + strFormat);

load(String filePath, LoadOptions loadOptions)

public static Image load(String filePath, LoadOptions loadOptions)

Loads a new image from the specified file path or URL. If filePath is a file path the method just opens the file. If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path or URL to load image from.
loadOptionsLoadOptionsThe load options.

Returns: Image - The loaded image.

load(String filePath)

public static Image load(String filePath)

Loads a new image from the specified file path or URL. If filePath is a file path the method just opens the file. If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path or URL to load image from.

Returns: Image - The loaded image.

Example: This example demonstrates the loading of an existing Image file into an instance of com. This example demonstrates the loading of an existing Image file into an instance of com.aspose.imaging.Image using file path specified

// Create Image instance and initialize it with an existing image file from disk location
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("C:\\temp\\sample.bmp");
try {
    // Do some image processing.
} finally {
    image.dispose();
}

load(RandomAccessFile file, LoadOptions loadOptions)

public static Image load(RandomAccessFile file, LoadOptions loadOptions)

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to load image from.
loadOptionsLoadOptionsThe load options.

Returns: Image - The loaded image.

load(RandomAccessFile file)

public static Image load(RandomAccessFile file)

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to load image from.

Returns: Image - The loaded image.

load(InputStream stream, LoadOptions loadOptions)

public static Image load(InputStream stream, LoadOptions loadOptions)

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to load image from.
loadOptionsLoadOptionsThe load options.

Returns: Image - The loaded image.

load(InputStream stream)

public static Image load(InputStream stream)

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to load image from.

Returns: Image - The loaded image.

Example: This example demonstrates the use of InputStream object to load an existing Image file

// Create an instance of FileInputStream
java.io.InputStream stream = new java.io.FileInputStream("C:\\temp\\sample.bmp");
try {
    // Create an instance of Image class and load an existing file through FileStream object by calling Load method
    com.aspose.imaging.Image image = com.aspose.imaging.Image.load(stream);
    try {
        // Do some image processing.
    } finally {
        image.dispose();
    }
} finally {
    stream.close();
}

getFileFormat(InputStream stream)

public static long getFileFormat(InputStream stream)

Gets the file format.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe 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. |

Returns: long - The determined file format.

Example: This example shows how to determine the image format without loading the entire image from a file stream.


// The helper class used in the main example below.
class Utils {
    // The helper method to get a string representation of the file format.
    public String getFileFormatString(long fileFormat) {
        if (fileFormat == com.aspose.imaging.FileFormat.Bmp) {
            return "BMP";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Gif) {
            return "GIF";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Dicom) {
            return "DICOM";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Djvu) {
            return "DJVU";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Dng) {
            return "DNG";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Png) {
            return "PNG";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Jpeg) {
            return "JPEG";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Jpeg2000) {
            return "JPEG2000";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Psd) {
            return "PSD";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Tiff) {
            return "Tiff";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Webp) {
            return "WEBP";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Cdr) {
            return "CDR";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Cmx) {
            return "CMX";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Emf) {
            return "EMF";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Wmf) {
            return "WMF";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Svg) {
            return "SVG";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Odg) {
            return "ODG";
        } else if (fileFormat == com.aspose.imaging.FileFormat.Eps) {
            return "EPS";
        } else {
            return "UNDEFINED";
        }
    }
}

// Here is the main example
Utils utils = new Utils();

String dir = "c:\\temp\\";

// Use a file stream
java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.bmp");
{
    long format = com.aspose.imaging.Image.getFileFormat(stream);
    System.out.println("The file format is " + utils.getFileFormatString(format));
}

// The following data is not a valid image stream, so GetFileFormat returns FileFormat.Undefined.
byte[] imageData = new byte[]{0, 0, 0, 0, 0, 0, 0, 0};
stream = new java.io.ByteArrayInputStream(imageData);
{
    long format = com.aspose.imaging.Image.getFileFormat(stream);
    System.out.println("The file format is " + utils.getFileFormatString(format));
}

// The output may look like this:
// The file format is BMP
// The file format is UNDEFINED

getFittingRectangle(Rectangle rectangle, int width, int height)

public static Rectangle getFittingRectangle(Rectangle rectangle, int width, int height)

Gets rectangle which fits the current image.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get fitting rectangle for.
widthintThe object width.
heightintThe object height.

Returns: Rectangle - The fitting rectangle or exception if no fitting rectangle can be found.

getFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)

public static Rectangle getFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)

Gets rectangle which fits the current image.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get fitting rectangle for.
pixelsint[]The 32-bit ARGB pixels.
widthintThe object width.
heightintThe object height.

Returns: Rectangle - The fitting rectangle or exception if no fitting rectangle can be found.

getProportionalWidth(int width, int height, int newHeight)

public static int getProportionalWidth(int width, int height, int newHeight)

Gets a proportional width.

Parameters:

ParameterTypeDescription
widthintThe width.
heightintThe height.
newHeightintThe new height.

Returns: int - The proportional width.

getProportionalHeight(int width, int height, int newWidth)

public static int getProportionalHeight(int width, int height, int newWidth)

Gets a proportional height.

Parameters:

ParameterTypeDescription
widthintThe width.
heightintThe height.
newWidthintThe new width.

Returns: int - The proportional height.

removeMetadata()

public void removeMetadata()

Removes metadata.

getBitsPerPixel()

public abstract int getBitsPerPixel()

Gets the image bits per pixel count.

Returns: int - The image bits per pixel count.

getBounds()

public Rectangle getBounds()

Gets the image bounds.

Returns: Rectangle - The image bounds.

getContainer()

public Image getContainer()

Gets the Image container.

Value: The Image container.

If this property is not null it indicates the image is contained within another image.

Returns: Image

getHeight()

public abstract int getHeight()

Gets the image height.

Returns: int - The image height.

getPalette()

public IColorPalette getPalette()

Gets the color palette. The color palette is not used when pixels are represented directly.

Returns: IColorPalette - The color palette.

setPalette(IColorPalette value)

public void setPalette(IColorPalette value)

Sets the color palette. The color palette is not used when pixels are represented directly.

Parameters:

ParameterTypeDescription
valueIColorPaletteThe color palette.

isUsePalette()

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.

Returns: boolean - a value indicating whether the image palette is used.

Example: Determine if the palette is used by the image.

try (Image image = Image.load("Sample.bmp"))
{
    if (image.isUsePalette())
    {
        System.out.println("The palette is used by the image");
    }
}

getSize()

public Size getSize()

Gets the image size.

Returns: Size - The image size.

Example: This example shows how to load a DJVU image from a file stream and print information about the pages.

String dir = "c:\\temp\\";

// Load a DJVU image from a file stream.
java.io.FileInputStream stream = new java.io.FileInputStream(dir + "sample.djvu");
try {
    com.aspose.imaging.fileformats.djvu.DjvuImage djvuImage = new com.aspose.imaging.fileformats.djvu.DjvuImage(stream);
    try {
        System.out.println("The total number of pages: " + djvuImage.getPages().length);
        System.out.println("The active page number:    " + djvuImage.getActivePage().getPageNumber());
        System.out.println("The first page number:     " + djvuImage.getFirstPage().getPageNumber());
        System.out.println("The last page number:      " + djvuImage.getLastPage().getPageNumber());

        for (com.aspose.imaging.fileformats.djvu.DjvuPage djvuPage : djvuImage.getPages()) {
            System.out.println("--------------------------------------------------");
            System.out.println("Page number:     " + djvuPage.getPageNumber());
            System.out.println("Page size:       " + djvuPage.getSize());
            System.out.println("Page raw format: " + djvuPage.getRawDataFormat());
        }
    } finally {
        djvuImage.dispose();
    }
} finally {
    stream.close();
}

//The output may look like this:
//The total number of pages: 2
//The active page number:    1
//The first page number:     1
//The last page number:      2
//--------------------------------------------------
//Page number:     1
//Page size:       { Width = 2481, Height = 3508}
//Page raw format: RgbIndexed1Bpp, used channels: 1
//--------------------------------------------------
//Page number:     2
//Page size:       { Width = 2481, Height = 3508}
//Page raw format: RgbIndexed1Bpp, used channels: 1

getWidth()

public abstract int getWidth()

Gets the image width.

Returns: int - The image width.

getInterruptMonitor()

public InterruptMonitor getInterruptMonitor()

Gets the interrupt monitor.

Returns: InterruptMonitor - the interrupt monitor.

setInterruptMonitor(InterruptMonitor value)

public void setInterruptMonitor(InterruptMonitor value)

Sets the interrupt monitor.

Parameters:

ParameterTypeDescription
valueInterruptMonitorthe interrupt monitor.

getBufferSizeHint()

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 buffers

Returns: int - the buffer size hint which is defined max allowed size for all internal buffers.

setBufferSizeHint(int value)

public 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 buffers

Parameters:

ParameterTypeDescription
valueintthe buffer size hint which is defined max allowed size for all internal buffers.

isAutoAdjustPalette()

public boolean isAutoAdjustPalette()

Gets a value indicating whether automatic adjust palette.

Returns: boolean - true if enable automatic adjust palette; otherwise, false.

setAutoAdjustPalette(boolean value)

public void setAutoAdjustPalette(boolean value)

Sets a value indicating whether automatic adjust palette.

Parameters:

ParameterTypeDescription
valuebooleantrue if enable automatic adjust palette; otherwise, false.

hasBackgroundColor()

public boolean hasBackgroundColor()

Gets a value indicating whether image has background color.

Returns: boolean

getFileFormat()

public long getFileFormat()

Easily retrieve the file format value with this user-friendly property. Ideal for developers seeking quick access to information about the file format.

Returns: long

getBackgroundColor()

public Color getBackgroundColor()

Gets or sets a value for the background color.

Returns: Color

setBackgroundColor(boolean value)

public void setBackgroundColor(boolean value)

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

Parameters:

ParameterTypeDescription
valueboolean

setBackgroundColor(Color value)

public void setBackgroundColor(Color value)

Gets or sets a value for the background color.

Parameters:

ParameterTypeDescription
valueColor

getIProgressEventHandler()

public final ProgressEventHandler getIProgressEventHandler()

Gets the progress event handler information.

Returns: ProgressEventHandler - the progress event handler information.

getProgressEventHandlerInfo()

public final ProgressEventHandlerInfo getProgressEventHandlerInfo()

Gets the progress event handler information.

Value: The progress event handler information.

Returns: ProgressEventHandlerInfo - the progress event handler information.

canSave(ImageOptionsBase options)

public boolean canSave(ImageOptionsBase options)

Determines whether image can be saved to the specified file format represented by the passed save options.

Parameters:

ParameterTypeDescription
optionsImageOptionsBaseThe save options to use.

Returns: boolean - true if image can be saved to the specified file format represented by the passed save options; otherwise, false.

Example: This example shows how to determine whether image can be saved to the specified file format represented by the passed save options.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    com.aspose.imaging.imageoptions.JpegOptions saveOptions = new com.aspose.imaging.imageoptions.JpegOptions();
    saveOptions.setQuality(50);

    // Determine whether the image can be saved to Jpeg
    boolean canSave = image.canSave(saveOptions);
} finally {
    image.dispose();
}

resize(int newWidth, int newHeight)

public void resize(int newWidth, int newHeight)

Resizes the image. The default ResizeType.NearestNeighbourResample is used.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.

Example: The following example shows how to resize a metafile (WMF and EMF).

String baseFolder = "c:\\temp\\";

String[] files = new String[]{"image3.emf", "image4.wmf"};
for (String fileName : files) {
    String inputFile = baseFolder + fileName;
    String outputFile = baseFolder + "Resize_" + fileName;
    com.aspose.imaging.fileformats.emf.MetaImage image = (com.aspose.imaging.fileformats.emf.MetaImage) com.aspose.imaging.Image.load(inputFile);
    try {
        image.resize(image.getWidth() / 4, image.getHeight() / 4);
        image.save(outputFile);
    } finally {
        image.close();
    }
}

Example: The following example shows how to resize SVG image and save it to PNG.

String dir = "c:\\aspose.imaging\\java\\issues\\1431\\";
String[] fileNames = new String[] {
                "Logotype.svg",
                "sample_car.svg",
                "rg1024_green_grapes.svg",
                "MidMarkerFigure.svg",
                "embeddedFonts.svg"
        };

com.aspose.imaging.PointF[] scales = new com.aspose.imaging.PointF[] {
                new com.aspose.imaging.PointF(0.5f, 0.5f),
                new com.aspose.imaging.PointF(1f, 1f),
                new com.aspose.imaging.PointF(2f, 2f),
                new com.aspose.imaging.PointF(3.5f, 9.2f),
        };

for (String inputFile : fileNames) {
    for (com.aspose.imaging.PointF scale : scales) {
        String outputFile = String.format("%s_%2.2f_%2.2f.png", inputFile, scale.getX(), scale.getY());
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + inputFile);
        try {
            image.resize((int) (image.getWidth() * scale.getX()), (int) (image.getHeight() * scale.getY()));
            image.save(dir + outputFile, new com.aspose.imaging.imageoptions.PngOptions());
        }
        finally {
            image.close();
        }
    }
}

resize(int newWidth, int newHeight, int resizeType)

public abstract void resize(int newWidth, int newHeight, int resizeType)

Resizes the image.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
resizeTypeintThe resize type.

Example: This example loads an image and resizes it using various resizing methods.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "upsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "downsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "upsample.bilinear.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using Bilinear resampling.
    image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "downsample.bilinear.gif");
} finally {
    image.dispose();
}

Example: Using a segment mask to speed up the segmentation process

// Masking export options
com.aspose.imaging.imageoptions.PngOptions exportOptions = new com.aspose.imaging.imageoptions.PngOptions();
exportOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
exportOptions.setSource(new com.aspose.imaging.sources.StreamSource());

com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();

// Use GraphCut clustering.
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.GraphCut);
maskingOptions.setDecompose(false);
maskingOptions.setArgs(new com.aspose.imaging.masking.options.AutoMaskingArgs());

// The background color will be transparent.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getTransparent());
maskingOptions.setExportOptions(exportOptions);

String dir = "c:\\temp\\";
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "BigImage.jpg");
try
{
    com.aspose.imaging.Size imageSize = image.getSize();

    // Reducing image size to speed up the segmentation process
    image.resizeHeightProportionally(600, com.aspose.imaging.ResizeType.HighQualityResample);

    // Create an instance of the ImageMasking class.
    com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);

    // Divide the source image into several clusters (segments).
    com.aspose.imaging.masking.result.MaskingResult maskingResult = masking.decompose(maskingOptions);
    try
    {
        // Getting the foreground mask
        com.aspose.imaging.RasterImage foregroundMask = maskingResult.get_Item(1).getMask();
        try
        {
            // Increase the size of the mask to the size of the original image
            foregroundMask.resize(imageSize.getWidth(), imageSize.getHeight(), com.aspose.imaging.ResizeType.NearestNeighbourResample);

            // Applying the mask to the original image to obtain a foreground segment
            com.aspose.imaging.RasterImage originImage = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "BigImage.jpg");
            try
            {
                com.aspose.imaging.masking.ImageMasking.applyMask(originImage, foregroundMask, maskingOptions);
                originImage.save(dir + "BigImage_foreground.png", exportOptions);
            }
            finally
            {
                originImage.close();
            }
        }
        finally
        {
            foregroundMask.close();
        }
    }
    finally
    {
        maskingResult.close();
    }
}
finally
{
    image.close();
}

Example: Resize image using specific Resize Type.

try (Image image = Image.load("Photo.jpg"))
{
    image.resize(640, 480, ResizeType.CatmullRom);
    image.save("ResizedPhoto.jpg");

    image.resize(1024, 768, ResizeType.CubicConvolution);
    image.save("ResizedPhoto2.jpg");

    ImageResizeSettings resizeSettings = new ImageResizeSettings();
    resizeSettings.setMode(ResizeType.CubicBSpline);
    resizeSettings.setFilterType(ImageFilterType.SmallRectangular);

    image.resize(800, 800, resizeSettings);
    image.save("ResizedPhoto3.jpg");
}

resize(int newWidth, int newHeight, ImageResizeSettings settings)

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

Resizes the image.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
settingsImageResizeSettingsThe resize settings.

Example: This example loads an image and resizes it using various resizing settings.

String dir = "c:\\temp\\";

com.aspose.imaging.ImageResizeSettings resizeSettings = new com.aspose.imaging.ImageResizeSettings();

// The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
resizeSettings.setMode(com.aspose.imaging.ResizeType.AdaptiveResample);

// The small rectangular filter
resizeSettings.setFilterType(com.aspose.imaging.ImageFilterType.SmallRectangular);

// The number of colors in the palette.
resizeSettings.setEntriesCount(256);

// The color quantization is not used
resizeSettings.setColorQuantizationMethod(com.aspose.imaging.ColorQuantizationMethod.None);

// The euclidian method
resizeSettings.setColorCompareMethod(com.aspose.imaging.ColorCompareMethod.Euclidian);

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using adaptive resampling.
    image.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings);
    image.save(dir + "downsample.adaptive.gif");
} finally {
    image.dispose();
}

Example: Resize image using specific Resize Type.

try (Image image = Image.load("Photo.jpg"))
{
    image.resize(640, 480, ResizeType.CatmullRom);
    image.save("ResizedPhoto.jpg");

    image.resize(1024, 768, ResizeType.CubicConvolution);
    image.save("ResizedPhoto2.jpg");

    ImageResizeSettings resizeSettings = new ImageResizeSettings();
    resizeSettings.setMode(ResizeType.CubicBSpline);
    resizeSettings.setFilterType(ImageFilterType.SmallRectangular);

    image.resize(800, 800, resizeSettings);
    image.save("ResizedPhoto3.jpg");
}

getDefaultOptions(Object[] args)

public ImageOptionsBase getDefaultOptions(Object[] args)

Gets the default options.

Parameters:

ParameterTypeDescription
argsjava.lang.Object[]The arguments.

Returns: ImageOptionsBase - Default options

getOriginalOptions()

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.

Returns: ImageOptionsBase - The options based on the original file settings.

resizeWidthProportionally(int newWidth)

public void resizeWidthProportionally(int newWidth)

Resizes the width proportionally. The default ResizeType.NearestNeighbourResample is used.

Parameters:

ParameterTypeDescription
newWidthintThe new width.

resizeHeightProportionally(int newHeight)

public void resizeHeightProportionally(int newHeight)

Resizes the height proportionally. The default ResizeType.NearestNeighbourResample is used.

Parameters:

ParameterTypeDescription
newHeightintThe new height.

resizeWidthProportionally(int newWidth, int resizeType)

public void resizeWidthProportionally(int newWidth, int resizeType)

Resizes the width proportionally.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
resizeTypeintType of the resize.

Example: This example loads an image and resizes it proportionally using various resizing methods. This example loads an image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "upsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "downsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "upsample.bilinear.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
{
    // Scale down by 2 times using Bilinear resampling.
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "downsample.bilinear.gif");
}

resizeHeightProportionally(int newHeight, int resizeType)

public void resizeHeightProportionally(int newHeight, int resizeType)

Resizes the height proportionally.

Parameters:

ParameterTypeDescription
newHeightintThe new height.
resizeTypeintType of the resize.

Example: This example loads an image and resizes it proportionally using various resizing methods. This example loads an image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "upsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
    image.save(dir + "upsample.nearestneighbour.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "upsample.bilinear.gif");
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
    // Scale down by 2 times using Bilinear resampling.
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
    image.save(dir + "downsample.bilinear.gif");
} finally {
    image.dispose();
}

Example: Using a segment mask to speed up the segmentation process

// Masking export options
com.aspose.imaging.imageoptions.PngOptions exportOptions = new com.aspose.imaging.imageoptions.PngOptions();
exportOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
exportOptions.setSource(new com.aspose.imaging.sources.StreamSource());

com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();

// Use GraphCut clustering.
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.GraphCut);
maskingOptions.setDecompose(false);
maskingOptions.setArgs(new com.aspose.imaging.masking.options.AutoMaskingArgs());

// The background color will be transparent.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getTransparent());
maskingOptions.setExportOptions(exportOptions);

String dir = "c:\\temp\\";
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "BigImage.jpg");
try
{
    com.aspose.imaging.Size imageSize = image.getSize();

    // Reducing image size to speed up the segmentation process
    image.resizeHeightProportionally(600, com.aspose.imaging.ResizeType.HighQualityResample);

    // Create an instance of the ImageMasking class.
    com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);

    // Divide the source image into several clusters (segments).
    com.aspose.imaging.masking.result.MaskingResult maskingResult = masking.decompose(maskingOptions);
    try
    {
        // Getting the foreground mask
        com.aspose.imaging.RasterImage foregroundMask = maskingResult.get_Item(1).getMask();
        try
        {
            // Increase the size of the mask to the size of the original image
            foregroundMask.resize(imageSize.getWidth(), imageSize.getHeight(), com.aspose.imaging.ResizeType.NearestNeighbourResample);

            // Applying the mask to the original image to obtain a foreground segment
            com.aspose.imaging.RasterImage originImage = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "BigImage.jpg");
            try
            {
                com.aspose.imaging.masking.ImageMasking.applyMask(originImage, foregroundMask, maskingOptions);
                originImage.save(dir + "BigImage_foreground.png", exportOptions);
            }
            finally
            {
                originImage.close();
            }
        }
        finally
        {
            foregroundMask.close();
        }
    }
    finally
    {
        maskingResult.close();
    }
}
finally
{
    image.close();
}

resizeWidthProportionally(int newWidth, ImageResizeSettings settings)

public void resizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Resizes the width proportionally.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
settingsImageResizeSettingsThe image resize settings.

resizeHeightProportionally(int newHeight, ImageResizeSettings settings)

public void resizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Resizes the height proportionally.

Parameters:

ParameterTypeDescription
newHeightintThe new height.
settingsImageResizeSettingsThe image resize settings.

rotateFlip(int rotateFlipType)

public abstract void rotateFlip(int rotateFlipType)

Rotates, flips, or rotates and flips the image.

Parameters:

ParameterTypeDescription
rotateFlipTypeintType of the rotation flip.

Example: This example demonstrates the use of Rotate operation on an image. This example demonstrates the use of Rotate operation on an image. Example loads an existing image file from some disk location and performs the Rotate operation on the image according to the value of Enum com.aspose.imaging.RotateFlipType

// Create an instance of image class and initialize it with an existing image file through File path
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("C:\\temp\\sample.bmp");
try {
    // Rotate the image at 180 degree about X axis
    image.rotateFlip(com.aspose.imaging.RotateFlipType.Rotate180FlipX);

    // Save all changes.
    image.save();
} finally {
    image.dispose();
}

save()

public final void save()

Saves the image data to the underlying stream.

Example: The following example shows how to save an entire BMP image or part of it to a file or stream.

String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;

    // Convert to a black-white image
    bmpImage.binarizeOtsu();

    // Save to the same location with default options.
    image.save();

    com.aspose.imaging.imageoptions.BmpOptions saveOptions = new com.aspose.imaging.imageoptions.BmpOptions();

    // A palette contains only two colors: Black and White in this case.
    saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.createMonochrome());

    // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
    saveOptions.setBitsPerPixel(1);

    // Save to another location with the specified options.
    image.save(dir + "sample.bw.palettized.bmp", saveOptions);

    // Save only the central part of the image.
    com.aspose.imaging.Rectangle bounds = new com.aspose.imaging.Rectangle(image.getWidth() / 4, image.getHeight() / 4, image.getWidth() / 2, image.getHeight() / 2);
    image.save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

    // Save the entire image to a memory stream
    java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
    try {
        image.save(stream, saveOptions);
        System.out.println("The size of the whole image in bytes: " + stream.size());
    } finally {
        stream.close();
    }

    // Save the central part of the image to a memory stream
    stream = new java.io.ByteArrayOutputStream();
    try {
        image.save(stream, saveOptions, bounds);
        System.out.println("The size of the central part of the image in bytes: " + stream.size());
    } finally {
        stream.close();
    }
} finally {
    image.close();
}

//The output may look like this:
//The size of the whole image in bytes: 1662
//The size of the central part of the image in bytes: 462

save(String filePath)

public void save(String filePath)

Saves the image to the specified file location.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path to save the image to.

save(String filePath, ImageOptionsBase options)

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.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path.
optionsImageOptionsBaseThe options.

Example: This example shows the simple steps to Save an Image. This example shows the simple steps to Save an Image. To demonstrate this operation, we load an existing file from some disk location and save the image in PSD format

// Load an existing file from disk.
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("C:\\temp\\sample.bmp");
try {
    // Save the Image as PSD to File Path with default PsdOptions settings
    image.save("C:\\temp\\output.psd", new com.aspose.imaging.imageoptions.PsdOptions());
} finally {
    image.dispose();
}

save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)

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.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path.
optionsImageOptionsBaseThe options.
boundsRectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.

Example: The following example loads a BMP image from a file, then saves a rectangular part of the image to a PNG file.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    // Save the upper half of the image to a PNG file.
    com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
    com.aspose.imaging.Rectangle bounds = new com.aspose.imaging.Rectangle(0, 0, image.getWidth(), image.getHeight() / 2);
    image.save(dir + "output.png", saveOptions, bounds);
} finally {
    image.dispose();
}

save(RandomAccessFile file, ImageOptionsBase options)

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.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to save the image’s data to.
optionsImageOptionsBaseThe options.

save(RandomAccessFile file, ImageOptionsBase optionsBase, Rectangle boundsRectangle)

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.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to save the image’s data to.
optionsBaseImageOptionsBaseThe save options.
boundsRectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.

save(OutputStream stream, ImageOptionsBase optionsBase)

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.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamThe stream to save the image’s data to.
optionsBaseImageOptionsBaseThe save options.

Example: This example shows the process of saving an Image to memory buffer. This example shows the process of saving an Image to memory buffer. To demonstrate this operation, example loads an existing file from some disk location and save the image in PSD format.

java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
try {            //Create an instance of image class and initialize it with an existing image file through File path
    com.aspose.imaging.Image image = com.aspose.imaging.Image.load("C:\\temp\\sample.bmp");
    try {
        //Save the image to PSD memory stream with default PsdOptions settings
        image.save(stream, new com.aspose.imaging.imageoptions.PsdOptions());
    } finally {
        image.dispose();
    }
} finally {
    stream.close();
}

save(OutputStream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)

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.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamThe stream to save the image’s data to.
optionsBaseImageOptionsBaseThe save options.
boundsRectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.

Example: The following example loads an image from a file, then saves a rectangular part of the image to a PNG file stream.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
    com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
    com.aspose.imaging.Rectangle bounds = new com.aspose.imaging.Rectangle(0, 0, image.getWidth(), image.getHeight() / 2);
    java.io.OutputStream outputStream = new java.io.FileOutputStream(dir + "sample.output.png");
    try {
        // Save the upper half of the image to a file stream.
        image.save(outputStream, saveOptions, bounds);
    } finally {
        outputStream.close();
    }
} finally {
    image.dispose();
}

setPalette(IColorPalette palette, boolean updateColors)

public abstract void setPalette(IColorPalette palette, boolean updateColors)

Sets the image palette.

Parameters:

ParameterTypeDescription
paletteIColorPaletteThe palette to set.
updateColorsbooleanif 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.

getSerializedStream(ImageOptionsBase imageOptions, Rectangle clippingRectangle, int[] pageNumber)

public InputStream getSerializedStream(ImageOptionsBase imageOptions, Rectangle clippingRectangle, int[] pageNumber)

Converts to aps.

Parameters:

ParameterTypeDescription
imageOptionsImageOptionsBaseThe image options.
clippingRectangleRectangleThe clipping rectangle.
pageNumberint[]The page number.

Returns: java.io.InputStream - The serialized stream