public class TiffImage extends RasterCachedMultipageImage implements IMultipageImageExt, com.aspose.internal.IMetadataContainer
Process Tagged Image File Format (TIFF) raster images with our API, offering comprehensive support for various resolutions and advanced editing capabilities like EXIF data manipulation and alpha channels. Normalize angles for scanned images, resize, transform to grayscale, and apply filters, gamma corrections and image parameters adjustments with ease. Seamlessly handle multi-frame TIFF files, create graphics paths, add shapes, and effortlessly save images to different formats.
Create Graphics Path from Path Resources in TIFF image.
try (TiffImage image = (TiffImage)Image.load("Bottle.tif"))
{
// Create the GraphicsPath using PathResources from TIFF image
GraphicsPath graphicsPath = PathResourceConverter.toGraphicsPath(
image.getActiveFrame().getPathResources().toArray(new PathResource[0]),
image.getActiveFrame().getSize());
Graphics graphics = new Graphics(image);
// Draw red line and save the image
graphics.drawPath(new Pen(Color.getRed(), 10), graphicsPath);
image.save("BottleWithRedBorder.tif");
}
| Constructor and Description |
|---|
TiffImage(TiffFrame frame)
Initialize a new object of the
TiffImage class, specifying the
frame parameter. |
TiffImage(TiffFrame[] frames)
Create a new instance of the
TiffImage class, providing a list of
frames as a parameter. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(TiffImage image)
Add the frames from the specified image seamlessly into the current frame,
consolidating their content and enhancing compositional flexibility.
|
void |
addFrame(TiffFrame frame)
Incorporate the specified frame seamlessly into the image, expanding its content
and versatility.
|
void |
addFrames(TiffFrame[] frames)
Integrate the array of frames seamlessly into the image, enriching its content and
versatility.
|
void |
addPage(RasterImage page)
Incorporate a new page into the existing image seamlessly, expanding its content
and versatility.
|
void |
adjustBrightness(int brightness)
Implement
brightness adjustment for the image, allowing the
modification of overall luminance levels. |
void |
adjustContrast(float contrast)
Enhance the contrast of the
Image instance,
amplifying the differences between its light and dark areas. |
void |
adjustGamma(float gamma)
Apply gamma correction to the image, adjusting pixel intensities to achieve
desired color balance.
|
void |
adjustGamma(float gammaRed,
float gammaGreen,
float gammaBlue)
Perform gamma correction on the image using individual coefficients for red,
green, and blue channels, allowing for fine-tuned adjustments of color balance
and contrast.
|
void |
alignResolutions()
Implement the AlignResolutions helper method to synchronize horizontal and
vertical resolutions, ensuring uniformity in image dimensions.
|
void |
binarizeBradley(double brightnessDifference,
int windowSize)
Implement binarization on the image employing Bradley's adaptive thresholding
algorithm with integral image thresholding.
|
void |
binarizeFixed(byte threshold)
Apply binarization to the image using a predefined threshold, converting it into
a binary image with distinct foreground and background regions.
|
void |
binarizeOtsu()
Utilize Otsu thresholding to perform binarization on the image, automatically
determining the optimal threshold value based on the image's histogram.
|
void |
crop(int leftShift,
int rightShift,
int topShift,
int bottomShift)
Perform cropping on the image by specifying shifts in the left, right, top, and
bottom directions.
|
void |
crop(Rectangle rectangle)
Crop the image using a specified rectangular region, allowing precise selection of
desired content.
|
void |
dither(int ditheringMethod,
int bitsCount,
IColorPalette customPalette)
Execute dithering on the current image to enhance its visual quality and reduce
color banding artifacts.
|
void |
filter(Rectangle rectangle,
FilterOptionsBase options)
Filter the content within the specified rectangle, applying a designated image
processing filter to enhance or modify the selected region.
|
TiffFrame |
getActiveFrame()
Manage the active frame seamlessly, facilitating dynamic navigation and
manipulation within the designated context.
|
int |
getByteOrder()
Toggle the byte order for TIFF files seamlessly, ensuring precise control over
data interpretation.
|
ExifData |
getExifData()
Access or modify EXIF data associated with the active frame seamlessly, empowering
precise control over image metadata.
|
long |
getFileFormat()
Retrieve the file format value associated with the image.
|
TiffFrame[] |
getFrames()
Retrieve an array of
TiffFrame instances, enabling comprehensive
access and manipulation of individual frames within the TIFF image. |
double |
getHorizontalResolution()
Retrieve the horizontal resolution of the specified
Image in pixels
per inch, facilitating precise adjustment and rendering capabilities. |
ImageOptionsBase |
getOriginalOptions()
Retrieve options derived from the original file settings, facilitating seamless
preservation of key parameters such as bit-depth and other essential attributes of
the original image.
|
int |
getPageCount()
Retrieve the total count of pages within the specified document, facilitating
efficient navigation and management of multipage content.
|
Image[] |
getPages()
Access the pages of the document seamlessly, enabling dynamic navigation and
manipulation within the content structure.
|
boolean |
getPremultiplyComponents()
Indicate if components necessitate premultiplication, ensuring efficient handling
of visual elements.
|
double |
getVerticalResolution()
Access the vertical resolution of the designated
Image in pixels per
inch, enabling precise adjustments and rendering optimizations. |
void |
grayscale()
Convert the image to its grayscale representation, transforming it into a
single-channel image where each pixel represents intensity.
|
boolean |
hasAlpha()
Determine whether the image has an alpha channel, providing crucial information
for rendering and compositing operations.
|
void |
insertFrame(int index,
TiffFrame frameToInsert)
Insert the new frame at the specified index within the frame sequence, ensuring
precise control over frame arrangement.
|
void |
normalizeAngle(boolean resizeProportionally,
Color backgroundColor)
Utilize the NormalizeAngle method specifically designed for scanned text documents
to rectify skewed scans, ensuring accurate alignment.
|
TiffFrame |
removeFrame(int index)
Effortlessly eliminate the frame identified by its index from the image sequence,
streamlining frame management within your application.
|
void |
removeFrame(TiffFrame frame)
Efficiently remove the specified frame from the image sequence, facilitating
streamlined frame management within your application.
|
void |
removeMetadata()
Removes this image instance metadata by setting this
IHasXmpData.XmpData(IHasXmpData.getXmpData()/IHasXmpData.setXmpData(XmpPacketWrapper))
value to null. |
TiffFrame |
replaceFrame(int index,
TiffFrame frameToReplace)
Substitute the frame at the designated position with another frame seamlessly,
facilitating dynamic frame management within the image sequence.
|
void |
resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Adjust the size of the image based on specified settings, allowing for precise
control over dimensions, aspect ratio, and scaling behavior.
|
void |
resizeHeightProportionally(int newHeight,
int resizeType)
Conduct a proportional adjustment of the image's height, preserving its aspect
ratio for consistent visual integrity.
|
void |
resizeProportional(int newWidth,
int newHeight,
int resizeType)
Conduct a proportional resize operation on the image, preserving its aspect ratio
while adjusting its dimensions.
|
void |
resizeWidthProportionally(int newWidth,
int resizeType)
Adjust the width of the image while maintaining its aspect ratio, ensuring
proportional resizing for optimal visual presentation.
|
void |
rotateFlip(int rotateFlipType)
Perform rotation, flipping, or a combination of both operations exclusively on the
active frame.
|
void |
setActiveFrame(TiffFrame value)
Manage the active frame seamlessly, facilitating dynamic navigation and
manipulation within the designated context.
|
void |
setByteOrder(int value)
Toggle the byte order for TIFF files seamlessly, ensuring precise control over
data interpretation.
|
void |
setExifData(ExifData value)
Access or modify EXIF data associated with the active frame seamlessly, empowering
precise control over image metadata.
|
void |
setHorizontalResolution(double value)
Modifies the horizontal resolution of the specified
Image in pixels
per inch, facilitating precise adjustment and rendering capabilities. |
void |
setPremultiplyComponents(boolean value)
Indicate if components necessitate premultiplication, ensuring efficient handling
of visual elements.
|
void |
setResolution(double dpiX,
double dpiY)
Establishes the resolution for the specified
RasterImage, enabling
precise control over image rendering and display properties. |
void |
setVerticalResolution(double value)
Access the vertical resolution of the designated
Image in pixels per
inch, enabling precise adjustments and rendering optimizations. |
analyzePercentageDigitalSignature, binarizeBradley, blend, cacheData, embedDigitalSignature, getBackgroundColor, getBitsPerPixel, getHeight, getImageOpacity, getPageExportingAction, getWidth, getXmpData, hasTransparentColor, isCached, isDigitalSigned, normalizeHistogram, replaceColor, replaceNonTransparentColors, resize, rotate, rotateFlipAll, setBackgroundColor, setPageExportingAction, setXmpDataautoBrightnessContrastblend, blend, blend, dither, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getModifyDate, getPixel, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, isDigitalSigned, isRawDataAvailable, isUsePalette, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialArgb64Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, readArgb32ScanLine, readScanLine, replaceColor, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setPalette, setPixel, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setTransparentColor, setTransparentColor, setUpdateXmpData, setUseRawData, toBitmap, writeArgb32ScanLine, writeScanLinecanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, getBounds, getBufferSizeHint, getContainer, getDefaultOptions, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalettegetDataStreamContainer, save, save, saveclose, dispose, getDisposedequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPageExportingAction, setPageExportingActiongetXmpData, setXmpDatapublic TiffImage(TiffFrame frame)
Initialize a new object of the TiffImage class, specifying the
frame parameter. This constructor facilitates the creation of a TiffImage
instance, allowing developers to specify the frame to be loaded or processed,
streamlining Tiff image handling tasks within their applications.
frame - The tiff frame to initialize image with.com.aspose.ms.System.ArgumentNullException - Tiff frame cannot be empty.This example shows how to create a TIFF image from scratch and save it to a file.
String dir = "c:\\temp\\";
com.aspose.imaging.imageoptions.TiffOptions createOptions =
new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
// Set 8 bits for each color component.
createOptions.setBitsPerSample(new int[]{8, 8, 8});
// Set the Big Endian byte order (Motorola)
createOptions.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.BigEndian);
// Set the LZW compression.
createOptions.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.Lzw);
// Set the RGB color model.
createOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
// All color components will be stored within a single plane.
createOptions.setPlanarConfiguration(com.aspose.imaging.fileformats.tiff.enums.TiffPlanarConfigs.Contiguous);
// Create a TIFF Frame of 100x100 px.
// Note that you don't have to dispose a frame explicitly if it is included into TiffImage.
// When the container is disposed all frames will be disposed automatically.
com.aspose.imaging.fileformats.tiff.TiffFrame firstFrame = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions, 100, 100);
// Fill the entire frame with the blue-yellow gradient.
com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
new com.aspose.imaging.Point(0, 0),
new com.aspose.imaging.Point(firstFrame.getWidth(), firstFrame.getHeight()),
com.aspose.imaging.Color.getBlue(),
com.aspose.imaging.Color.getYellow());
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(firstFrame);
graphics.fillRectangle(gradientBrush, firstFrame.getBounds());
// Create a TIFF image.
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = new com.aspose.imaging.fileformats.tiff.TiffImage(firstFrame);
try {
tiffImage.save(dir + "output.tif");
} finally {
tiffImage.dispose();
}
public TiffImage(TiffFrame[] frames)
Create a new instance of the TiffImage class, providing a list of
frames as a parameter. This constructor enables the initialization of a TiffImage
object with multiple frames, facilitating efficient handling and processing of
TIFF image sequences within software applications.
frames - The frames.com.aspose.ms.System.ArgumentNullException - framesThis example shows how to create a TIFF image with 2 frames and save it to a file.
String dir = "c:\\temp\\";
// Options for the first frame
com.aspose.imaging.imageoptions.TiffOptions createOptions1 =
new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
// Set 8 bits for each color component.
createOptions1.setBitsPerSample(new int[]{8, 8, 8});
// Set the Big Endian byte order (Motorola)
createOptions1.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.BigEndian);
// Set the LZW compression.
createOptions1.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.Lzw);
// Set the RGB color model.
createOptions1.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
// All color components will be stored within a single plane.
createOptions1.setPlanarConfiguration(com.aspose.imaging.fileformats.tiff.enums.TiffPlanarConfigs.Contiguous);
// Create the first TIFF frame of 100x100 px.
// Note that you don't have to dispose frames explicitly if they are included into TiffImage.
// When the container is disposed all frames will be disposed automatically.
com.aspose.imaging.fileformats.tiff.TiffFrame frame1 = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions1, 100, 100);
// Fill the first frame with the blue-yellow gradient.
com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
new com.aspose.imaging.Point(0, 0),
new com.aspose.imaging.Point(frame1.getWidth(), frame1.getHeight()),
com.aspose.imaging.Color.getBlue(),
com.aspose.imaging.Color.getYellow());
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(frame1);
graphics.fillRectangle(gradientBrush, frame1.getBounds());
// Options for the first frame
com.aspose.imaging.imageoptions.TiffOptions createOptions2
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
// Set 1 bit per pixel for a B/W image.
createOptions2.setBitsPerSample(new int[]{1});
// Set the Little Endian byte order (Intel)
createOptions2.setByteOrder(com.aspose.imaging.fileformats.tiff.enums.TiffByteOrder.LittleEndian);
// Set the CCITT Group 3 Fax compression.
createOptions2.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.CcittFax3);
// Set the B/W color model where 0 is black, 1 is white.
createOptions2.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.MinIsBlack);
// Create the second TIFF frame of 200x200px.
com.aspose.imaging.fileformats.tiff.TiffFrame frame2 = new com.aspose.imaging.fileformats.tiff.TiffFrame(createOptions2, 200, 200);
// Fill the second frame with the blue-yellow gradient.
// It will be automatically converted to the B/W format due to the corresponding settings of the frame.
com.aspose.imaging.Graphics graphics2 = new com.aspose.imaging.Graphics(frame2);
graphics2.fillRectangle(gradientBrush, frame2.getBounds());
// Create a TIFF image.
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = new com.aspose.imaging.fileformats.tiff.TiffImage(
new com.aspose.imaging.fileformats.tiff.TiffFrame[]{frame1, frame2});
try {
tiffImage.save(dir + "output.mutliframe.tif");
} finally {
tiffImage.dispose();
}
public long getFileFormat()
Retrieve the file format value associated with the image. This property serves as a critical aspect of image metadata retrieval, allowing software applications to identify and interpret the format of the image data efficiently.
getFileFormat in class ImageFileFormatpublic boolean getPremultiplyComponents()
Indicate if components necessitate premultiplication, ensuring efficient handling of visual elements. Enhance rendering processes by toggling this property, streamlining graphic workflows for optimized performance.
getPremultiplyComponents in class RasterImagetrue if components must be premultiplied; otherwise, false.public void setPremultiplyComponents(boolean value)
Indicate if components necessitate premultiplication, ensuring efficient handling of visual elements. Enhance rendering processes by toggling this property, streamlining graphic workflows for optimized performance.
setPremultiplyComponents in class RasterImagevalue - true if components must be premultiplied; otherwise, false.The following example creates a new TIFF image, saves the specified semi-transparent pixels, then loads those pixels and gets final colors in the premultiplied form.
int imageWidth = 3;
int imageHeight = 2;
com.aspose.imaging.Color[] colors = new com.aspose.imaging.Color[]
{
com.aspose.imaging.Color.fromArgb(127, 255, 0, 0),
com.aspose.imaging.Color.fromArgb(127, 0, 255, 0),
com.aspose.imaging.Color.fromArgb(127, 0, 0, 255),
com.aspose.imaging.Color.fromArgb(127, 255, 255, 0),
com.aspose.imaging.Color.fromArgb(127, 255, 0, 255),
com.aspose.imaging.Color.fromArgb(127, 0, 255, 255),
};
com.aspose.imaging.imageoptions.TiffOptions createOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.TiffDeflateRgba);
createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]), true));
com.aspose.imaging.fileformats.tiff.TiffImage image =
(com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createOptions, imageWidth, imageHeight);
try {
// Save pixels for the whole image.
image.savePixels(image.getBounds(), colors);
// The pixels are stored in the original image in the non-premultiplied form.
// Need to specify the corresponding option explicitly to obtain premultiplied color components.
// The premultiplied color components are calculated by the formulas:
// red = original_red * alpha / 255;
// green = original_green * alpha / 255;
// blue = original_blue * alpha / 255;
image.setPremultiplyComponents(true);
com.aspose.imaging.Color[] premultipliedColors = image.loadPixels(image.getBounds());
for (int i = 0; i < colors.length; i++) {
System.out.println("Original color: " + colors[i].toString());
System.out.println("Premultiplied color: " + premultipliedColors[i].toString());
}
} finally {
image.dispose();
}
//The output will look like this:
//Original color: Color [A=127, R=255, G=0, B=0]
//Premultiplied color: Color [A=127, R=127, G=0, B=0]
//Original color: Color [A=127, R=0, G=255, B=0]
//Premultiplied color: Color [A=127, R=0, G=127, B=0]
//Original color: Color [A=127, R=0, G=0, B=255]
//Premultiplied color: Color [A=127, R=0, G=0, B=127]
//Original color: Color [A=127, R=255, G=255, B=0]
//Premultiplied color: Color [A=127, R=127, G=127, B=0]
//Original color: Color [A=127, R=255, G=0, B=255]
//Premultiplied color: Color [A=127, R=127, G=0, B=127]
//Original color: Color [A=127, R=0, G=255, B=255]
//Premultiplied color: Color [A=127, R=0, G=127, B=127]
public final int getByteOrder()
Toggle the byte order for TIFF files seamlessly, ensuring precise control over data interpretation. Empower your applications with the flexibility to adapt to diverse file specifications, enhancing compatibility and efficiency in data processing.
TiffByteOrderpublic final void setByteOrder(int value)
Toggle the byte order for TIFF files seamlessly, ensuring precise control over data interpretation. Empower your applications with the flexibility to adapt to diverse file specifications, enhancing compatibility and efficiency in data processing.
value - The tiff byte order.TiffByteOrderpublic double getHorizontalResolution()
Retrieve the horizontal resolution of the specified Image in pixels
per inch, facilitating precise adjustment and rendering capabilities. Access
essential image metadata effortlessly, empowering streamlined image processing
workflows for enhanced user experiences.
getHorizontalResolution in class RasterImageNote by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Get horizontal and vertical resolution of the TiffImage.
double horizontalResolution = tiffImage.getHorizontalResolution();
double verticalResolution = tiffImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
tiffImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void setHorizontalResolution(double value)
Modifies the horizontal resolution of the specified Image in pixels
per inch, facilitating precise adjustment and rendering capabilities. Access
essential image metadata effortlessly, empowering streamlined image processing
workflows for enhanced user experiences.
setHorizontalResolution in class RasterImagevalue - The horizontal resolution.
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
public double getVerticalResolution()
Access the vertical resolution of the designated Image in pixels per
inch, enabling precise adjustments and rendering optimizations. Utilize essential
image data effortlessly to streamline image processing workflows, ensuring
superior quality and performance in your applications.
getVerticalResolution in class RasterImageNote by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Get horizontal and vertical resolution of the TiffImage.
double horizontalResolution = tiffImage.getHorizontalResolution();
double verticalResolution = tiffImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
tiffImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void setVerticalResolution(double value)
Access the vertical resolution of the designated Image in pixels per
inch, enabling precise adjustments and rendering optimizations. Utilize essential
image data effortlessly to streamline image processing workflows, ensuring
superior quality and performance in your applications.
setVerticalResolution in class RasterImagevalue - The vertical resolution.
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
public final TiffFrame getActiveFrame()
Manage the active frame seamlessly, facilitating dynamic navigation and manipulation within the designated context. Empower your application to interact efficiently with multimedia content, enhancing user engagement and productivity.
The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false));
createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
createTiffOptions.setBitsPerSample(new int[]{8, 8, 8});
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100);
try {
// This is Font and Brush for drawing text on individual frames.
com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite());
// Create 5 frames
for (int i = 1; i <= 5; i++) {
com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions();
createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
// Create a PNG image and draw the number of page on it.
com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100);
com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage);
gr.drawString(Integer.toString(i), font, brush, 10, 10);
// Create a frame based on the PNG image.
com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);
// Add the frame to the TIFF image.
tiffImage.addFrame(frame);
}
// The image was created with a single default frame. Let's remove it.
com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
tiffImage.removeFrame(0);
// Don't forget to dispose the frame if you won't add it to some other TiffImage
activeFrame.dispose();
tiffImage.save();
} finally {
tiffImage.dispose();
}
public final void setActiveFrame(TiffFrame value)
Manage the active frame seamlessly, facilitating dynamic navigation and manipulation within the designated context. Empower your application to interact efficiently with multimedia content, enhancing user engagement and productivity.
value - Active frame.The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false));
createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
createTiffOptions.setBitsPerSample(new int[]{8, 8, 8});
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100);
try {
// This is Font and Brush for drawing text on individual frames.
com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite());
// Create 5 frames
for (int i = 1; i <= 5; i++) {
com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions();
createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
// Create a PNG image and draw the number of page on it.
com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100);
com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage);
gr.drawString(Integer.toString(i), font, brush, 10, 10);
// Create a frame based on the PNG image.
com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);
// Add the frame to the TIFF image.
tiffImage.addFrame(frame);
}
// The image was created with a single default frame. Let's remove it.
com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
tiffImage.removeFrame(0);
// Don't forget to dispose the frame if you won't add it to some other TiffImage
activeFrame.dispose();
tiffImage.save();
} finally {
tiffImage.dispose();
}
public final TiffFrame[] getFrames()
Retrieve an array of TiffFrame instances, enabling comprehensive
access and manipulation of individual frames within the TIFF image. Harness the
power of this array to streamline image processing workflows, ensuring precise
control and optimization of visual content.
TiffFrame array.The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false));
createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
createTiffOptions.setBitsPerSample(new int[]{8, 8, 8});
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100);
try {
// This is Font and Brush for drawing text on individual frames.
com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite());
// Create 5 frames
for (int i = 1; i <= 5; i++) {
com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions();
createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
// Create a PNG image and draw the number of page on it.
com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100);
com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage);
gr.drawString(Integer.toString(i), font, brush, 10, 10);
// Create a frame based on the PNG image.
com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);
// Add the frame to the TIFF image.
tiffImage.addFrame(frame);
}
// The image was created with a single default frame. Let's remove it.
com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
tiffImage.removeFrame(0);
// Don't forget to dispose the frame if you won't add it to some other TiffImage
activeFrame.dispose();
tiffImage.save();
} finally {
tiffImage.dispose();
}
public final ExifData getExifData()
Access or modify EXIF data associated with the active frame seamlessly, empowering precise control over image metadata. Enhance your application's capabilities by integrating this feature, ensuring accurate preservation and customization of essential image information.
getExifData in interface IHasExifDatapublic final void setExifData(ExifData value)
Access or modify EXIF data associated with the active frame seamlessly, empowering precise control over image metadata. Enhance your application's capabilities by integrating this feature, ensuring accurate preservation and customization of essential image information.
setExifData in interface IHasExifDatavalue - Exif instance.public int getPageCount()
Retrieve the total count of pages within the specified document, facilitating efficient navigation and management of multipage content. Incorporate this functionality to enhance user experience, enabling seamless access to comprehensive document structures.
getPageCount in interface IMultipageImagegetPageCount in class RasterCachedMultipageImagepublic Image[] getPages()
Access the pages of the document seamlessly, enabling dynamic navigation and manipulation within the content structure. Empower your application with efficient access to individual pages, facilitating streamlined document processing and enhanced user interaction.
getPages in interface IMultipageImagegetPages in class RasterCachedMultipageImagepublic boolean hasAlpha()
Determine whether the image has an alpha channel, providing crucial information for rendering and compositing operations. Integrate this feature to optimize visual processing workflows, ensuring accurate representation and manipulation of transparent elements.
hasAlpha in class RasterCachedMultipageImagetrue if there is an alpha channel.The following example loads a TIFF image and prints information about raw data format and alpha channel.
String dir = "c:\\temp\\";
String fileName = dir + "sample.tif";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// If the active TIFF frame has alpha channel, then the entire TIFF image is considered to have alpha channel.
System.out.printf("ImageFile=%s, FileFormat=%s, HasAlpha=%s\r\n", fileName, tiffImage.getRawDataFormat(), tiffImage.hasAlpha());
int i = 0;
for (com.aspose.imaging.fileformats.tiff.TiffFrame frame : tiffImage.getFrames()) {
System.out.printf("Frame=%s, FileFormat=%s, HasAlpha=%s\r\n", ++i, frame.getRawDataFormat(), frame.hasAlpha());
}
} finally {
image.dispose();
}
// The output may look like this:
// ImageFile=c:\temp\sample.tif, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
// Frame=1, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
// Frame=2, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
public void removeMetadata()
Removes this image instance metadata by setting this
IHasXmpData.XmpData(IHasXmpData.getXmpData()/IHasXmpData.setXmpData(XmpPacketWrapper))
value to null.
removeMetadata in class RasterImagepublic ImageOptionsBase getOriginalOptions()
Retrieve options derived from the original file settings, facilitating seamless
preservation of key parameters such as bit-depth and other essential attributes of
the original image. Utilize this method to maintain fidelity and consistency in
image processing tasks, ensuring optimal results without unnecessary alterations.
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.
getOriginalOptions in class ImageTiffImageException - There is no original options that can be extracted from imagepublic void addPage(RasterImage page)
Incorporate a new page into the existing image seamlessly, expanding its content and versatility. Utilize this method to enhance document composition and management, empowering efficient handling of multipage images within your application.
addPage in interface IMultipageImageExtpage - The page to add.com.aspose.ms.System.ArgumentNullException - page is null.public final void alignResolutions()
Implement the AlignResolutions helper method to synchronize horizontal and vertical resolutions, ensuring uniformity in image dimensions. This functionality facilitates streamlined image processing workflows by harmonizing resolution parameters, optimizing visual quality and consistency across various platforms and devices.
public void setResolution(double dpiX,
double dpiY)
Establishes the resolution for the specified RasterImage, enabling
precise control over image rendering and display properties. Integrate this
functionality to optimize visual output and ensure compatibility with diverse
output devices and platforms, enhancing the overall user experience.
setResolution in class RasterImagedpiX - The horizontal resolution, in dots per inch, of the RasterImage.dpiY - The vertical resolution, in dots per inch, of the RasterImage.The following example shows how to set horizontal/vertical resolution of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Get horizontal and vertical resolution of the TiffImage.
double horizontalResolution = tiffImage.getHorizontalResolution();
double verticalResolution = tiffImage.getVerticalResolution();
System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
// Use the SetResolution method for updating both resolution values in a single call.
System.out.println("Set resolution values to 96 dpi");
tiffImage.setResolution(96.0, 96.0);
System.out.println("The horizontal resolution, in pixels per inch: " + tiffImage.getHorizontalResolution());
System.out.println("The vertical resolution, in pixels per inch: " + tiffImage.getVerticalResolution());
}
} finally {
image.dispose();
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 96.0
// The vertical resolution, in pixels per inch: 96.0
public void normalizeAngle(boolean resizeProportionally,
Color backgroundColor)
Utilize the NormalizeAngle method specifically designed for scanned text documents
to rectify skewed scans, ensuring accurate alignment. Seamlessly
integrate this functionality into your text processing workflows to enhance
document readability and quality, improving overall efficiency in text recognition
and analysis tasks.
This method uses RasterImage.getSkewAngle() and RasterImage.rotate(float, boolean, Color) methods.
normalizeAngle in class RasterCachedMultipageImageresizeProportionally - if set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.backgroundColor - Color of the background.public final void addFrame(TiffFrame frame)
Incorporate the specified frame seamlessly into the image, expanding its content and versatility. Utilize this method to enhance image composition and management, empowering efficient handling of multi-frame images within your application.
frame - The frame to add.The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false));
createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
createTiffOptions.setBitsPerSample(new int[]{8, 8, 8});
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100);
try {
// This is Font and Brush for drawing text on individual frames.
com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite());
// Create 5 frames
for (int i = 1; i <= 5; i++) {
com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions();
createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
// Create a PNG image and draw the number of page on it.
com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100);
com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage);
gr.drawString(Integer.toString(i), font, brush, 10, 10);
// Create a frame based on the PNG image.
com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);
// Add the frame to the TIFF image.
tiffImage.addFrame(frame);
}
// The image was created with a single default frame. Let's remove it.
com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
tiffImage.removeFrame(0);
// Don't forget to dispose the frame if you won't add it to some other TiffImage
activeFrame.dispose();
tiffImage.save();
} finally {
tiffImage.dispose();
}
public final void add(TiffImage image)
Add the frames from the specified image seamlessly into the current frame, consolidating their content and enhancing compositional flexibility. Integrate this method to streamline frame management and manipulation within your application, facilitating efficient handling of multi-frame images.
image - The source image.public final void addFrames(TiffFrame[] frames)
Integrate the array of frames seamlessly into the image, enriching its content and versatility. Utilize this method to enhance image composition and management, enabling efficient handling of multi-frame images within your application.
frames - The frames array to addpublic final void insertFrame(int index,
TiffFrame frameToInsert)
Insert the new frame at the specified index within the frame sequence, ensuring precise control over frame arrangement. Employ this method to manage frame sequences effectively, facilitating dynamic manipulation and organization of image content within your application.
index - Index of new frame in list of framesframeToInsert - The frame To Insert.public final TiffFrame replaceFrame(int index, TiffFrame frameToReplace)
Substitute the frame at the designated position with another frame seamlessly, facilitating dynamic frame management within the image sequence. Integrate this method to enhance flexibility and precision in frame manipulation, ensuring optimal organization and presentation of image content within your application.
index - The zero based frame position.frameToReplace - The frame to replace.
Note: do not forget to dispose/close the frame if you will not add it to some other TiffImage.
public final TiffFrame removeFrame(int index)
Effortlessly eliminate the frame identified by its index from the image sequence, streamlining frame management within your application. Integrate this functionality to enhance efficiency and precision in frame manipulation, facilitating seamless organization and presentation of image content.
index - Index of frame to be removed.
The following example shows how to compose a mutlipage TIFF from individual raster images.
com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
= new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("c:\\temp\\multipage.tif", false));
createTiffOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.Rgb);
createTiffOptions.setBitsPerSample(new int[]{8, 8, 8});
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.create(createTiffOptions, 100, 100);
try {
// This is Font and Brush for drawing text on individual frames.
com.aspose.imaging.Font font = new com.aspose.imaging.Font("Arial", 64);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite());
// Create 5 frames
for (int i = 1; i <= 5; i++) {
com.aspose.imaging.imageoptions.PngOptions createPngOptions = new com.aspose.imaging.imageoptions.PngOptions();
createPngOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
// Create a PNG image and draw the number of page on it.
com.aspose.imaging.fileformats.png.PngImage pngImage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image.create(createPngOptions, 100, 100);
com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(pngImage);
gr.drawString(Integer.toString(i), font, brush, 10, 10);
// Create a frame based on the PNG image.
com.aspose.imaging.fileformats.tiff.TiffFrame frame = new com.aspose.imaging.fileformats.tiff.TiffFrame(pngImage);
// Add the frame to the TIFF image.
tiffImage.addFrame(frame);
}
// The image was created with a single default frame. Let's remove it.
com.aspose.imaging.fileformats.tiff.TiffFrame activeFrame = tiffImage.getActiveFrame();
tiffImage.setActiveFrame(tiffImage.getFrames()[1]);
tiffImage.removeFrame(0);
// Don't forget to dispose the frame if you won't add it to some other TiffImage
activeFrame.dispose();
tiffImage.save();
} finally {
tiffImage.dispose();
}
public final void removeFrame(TiffFrame frame)
Efficiently remove the specified frame from the image sequence, facilitating streamlined frame management within your application. Integrate this functionality to enhance precision and flexibility in frame manipulation, ensuring seamless organization and presentation of image content.
frame - The frame to remove.
public final void resizeProportional(int newWidth,
int newHeight,
int resizeType)
Conduct a proportional resize operation on the image, preserving its aspect ratio
while adjusting its dimensions. Employ this method to dynamically scale images
within your application, ensuring consistent visual representation of content
integrity.
The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.
newWidth - The new width.newHeight - The new height.resizeType - The resize type.ResizeTypepublic void resizeWidthProportionally(int newWidth,
int resizeType)
Adjust the width of the image while maintaining its aspect ratio, ensuring proportional resizing for optimal visual presentation. Utilize this method to dynamically scale images within your application, facilitating consistent and aesthetically pleasing rendering across various display contexts.
resizeWidthProportionally in class RasterCachedMultipageImagenewWidth - The new width.resizeType - Type of the resize.ResizeTypeThis example loads a TIFF 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.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale up by 2 times using Nearest Neighbour resampling.
image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
// Save to PNG with the default options.
image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale down by 2 times using Nearest Neighbour resampling.
image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
// Save to PNG with the default options.
image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale up by 2 times using Bilinear resampling.
image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample);
// Save to PNG with the default options.
image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale down by 2 times using Bilinear resampling.
image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample);
// Save to PNG with the default options.
image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void resizeHeightProportionally(int newHeight,
int resizeType)
Conduct a proportional adjustment of the image's height, preserving its aspect ratio for consistent visual integrity. Employ this method to dynamically resize images within your application, ensuring optimal display across diverse platforms and devices without compromising content quality.
resizeHeightProportionally in class RasterCachedMultipageImagenewHeight - The new height.resizeType - Type of the resize.ResizeTypeThis example loads a TIFF 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.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale up by 2 times using Nearest Neighbour resampling.
image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
// Save to PNG with the default options.
image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale down by 2 times using Nearest Neighbour resampling.
image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
// Save to PNG with the default options.
image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale up by 2 times using Bilinear resampling.
image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
// Save to PNG with the default options.
image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
// Scale down by 2 times using Bilinear resampling.
image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
// Save to PNG with the default options.
image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void rotateFlip(int rotateFlipType)
Perform rotation, flipping, or a combination of both operations exclusively on the active frame. This method allows precise manipulation of individual frames within the image sequence, enhancing flexibility in image editing and composition within your application.
rotateFlip in class RasterCachedMultipageImagerotateFlipType - The rotation and flipping type.RotateFlipTypeThis example loads a TIFF image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.
String dir = "c:\\temp\\";
// This is a helper class.
class Utils {
// Gets a string representation of the rotate flip type.
public String rotateFlipTypeToString(int rotateFilpType) {
switch (rotateFilpType) {
case com.aspose.imaging.RotateFlipType.RotateNoneFlipNone:
return "RotateNoneFlipNone";
case com.aspose.imaging.RotateFlipType.Rotate90FlipNone:
return "Rotate90FlipNone";
case com.aspose.imaging.RotateFlipType.Rotate180FlipNone:
return "Rotate180FlipNone";
case com.aspose.imaging.RotateFlipType.Rotate270FlipNone:
return "Rotate270FlipNone";
case com.aspose.imaging.RotateFlipType.RotateNoneFlipX:
return "RotateNoneFlipX";
case com.aspose.imaging.RotateFlipType.Rotate90FlipX:
return "Rotate90FlipX";
case com.aspose.imaging.RotateFlipType.Rotate180FlipX:
return "Rotate180FlipX";
case com.aspose.imaging.RotateFlipType.Rotate270FlipX:
return "Rotate270FlipX";
case com.aspose.imaging.RotateFlipType.RotateNoneFlipY:
return "RotateNoneFlipY";
case com.aspose.imaging.RotateFlipType.Rotate90FlipY:
return "Rotate90FlipY";
case com.aspose.imaging.RotateFlipType.Rotate180FlipY:
return "Rotate180FlipY";
case com.aspose.imaging.RotateFlipType.Rotate270FlipY:
return "Rotate270FlipY";
case com.aspose.imaging.RotateFlipType.RotateNoneFlipXY:
return "RotateNoneFlipXY";
case com.aspose.imaging.RotateFlipType.Rotate90FlipXY:
return "Rotate90FlipXY";
case com.aspose.imaging.RotateFlipType.Rotate180FlipXY:
return "Rotate180FlipXY";
case com.aspose.imaging.RotateFlipType.Rotate270FlipXY:
return "Rotate270FlipXY";
default:
throw new java.lang.IllegalArgumentException("rotateFlipType");
}
}
}
// Here is the main example
Utils utils = new Utils();
int[] rotateFlipTypes = new int[]
{
com.aspose.imaging.RotateFlipType.Rotate90FlipNone,
com.aspose.imaging.RotateFlipType.Rotate90FlipX,
com.aspose.imaging.RotateFlipType.Rotate90FlipXY,
com.aspose.imaging.RotateFlipType.Rotate90FlipY,
};
for (int rotateFlipType : rotateFlipTypes) {
// Rotate, flip and save to the output file.
com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
image.rotateFlip(rotateFlipType);
image.save(dir + "sample." + utils.rotateFlipTypeToString(rotateFlipType) + ".png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
}
public void dither(int ditheringMethod,
int bitsCount,
IColorPalette customPalette)
Execute dithering on the current image to enhance its visual quality and reduce color banding artifacts. Integrate this method into your image processing workflow to ensure smoother transitions between colors, resulting in improved overall image appearance and clarity.
dither in class RasterCachedMultipageImageditheringMethod - The dithering method.bitsCount - The final bits count for dithering.customPalette - The custom palette for dithering.DitheringMethodThe following example loads a TIFF image and performs threshold and floyd dithering using different palette depth.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Perform threshold dithering using 4-bit color palette which contains 16 colors.
// The more bits specified the higher quality and the bigger size of the output image.
// Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
tiffImage.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 4, null);
tiffImage.save(dir + "sample.ThresholdDithering4.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Perform floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
// The more bits specified the higher quality and the bigger size of the output image.
// Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
tiffImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1, null);
tiffImage.save(dir + "sample.FloydSteinbergDithering1.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void crop(Rectangle rectangle)
Crop the image using a specified rectangular region, allowing precise selection of desired content. Integrate this method into your image processing workflow to efficiently remove unwanted areas and focus on essential details, enhancing the overall clarity and composition of the image.
crop in class RasterCachedMultipageImagerectangle - The rectangle.The following example crops a TIFF image. The cropping area is be specified via Aspose.Imaging.Rectangle.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Crop the image. The cropping area is the rectangular central area of the image.
com.aspose.imaging.Rectangle area = new com.aspose.imaging.Rectangle(
tiffImage.getWidth() / 4, tiffImage.getHeight() / 4, tiffImage.getWidth() / 2, tiffImage.getHeight() / 2);
tiffImage.crop(area);
// Save the cropped image to PNG
tiffImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void crop(int leftShift,
int rightShift,
int topShift,
int bottomShift)
Perform cropping on the image by specifying shifts in the left, right, top, and bottom directions. This method enables precise selection of the desired portion of the image, facilitating efficient removal of unwanted areas and focusing on essential content. Integrate this functionality into your image processing pipeline to enhance clarity and composition as needed within your application.
crop in class RasterCachedMultipageImageleftShift - The left shift.rightShift - The right shift.topShift - The top shift.bottomShift - The bottom shift.The following example crops a TIFF image. The cropping area is specified via Left, Top, Right, Bottom margins.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Crop again. Set a margin of 10% of the image size.
int horizontalMargin = tiffImage.getWidth() / 10;
int verticalMargin = tiffImage.getHeight() / 10;
tiffImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);
// Save the cropped image to PNG.
tiffImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void binarizeFixed(byte threshold)
Apply binarization to the image using a predefined threshold, converting it into a binary image with distinct foreground and background regions. Incorporate this method into your image processing workflow to facilitate segmentation and feature extraction tasks, enhancing the accuracy and efficiency of image analysis within your application.
binarizeFixed in class RasterCachedMultipageImagethreshold - Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of
255 will be assigned to it, 0 otherwise.The following example binarizes a TIFF image with the predefined threshold. Binarized images contain only 2 colors - black and white.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Binarize the image with a threshold value of 127.
// If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
tiffImage.binarizeFixed((byte) 127);
tiffImage.save(dir + "sample.BinarizeFixed.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void binarizeOtsu()
Utilize Otsu thresholding to perform binarization on the image, automatically determining the optimal threshold value based on the image's histogram. Integrate this method into your image processing workflow to achieve effective segmentation and feature extraction, enhancing the accuracy and reliability of image analysis tasks within your application.
binarizeOtsu in class RasterCachedMultipageImageThe following example binarizes a TIFF image with Otsu thresholding. Binarized images contain only 2 colors - black and white.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Binarize the image with Otsu thresholding.
tiffImage.binarizeOtsu();
tiffImage.save(dir + "sample.BinarizeOtsu.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void binarizeBradley(double brightnessDifference,
int windowSize)
Implement binarization on the image employing Bradley's adaptive thresholding algorithm with integral image thresholding. This approach dynamically computes local thresholds based on the image's neighborhood, enhancing adaptability to varying lighting conditions and ensuring robust segmentation for subsequent processing tasks within your application.
binarizeBradley in class RasterCachedMultipageImagebrightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels
centered around this pixel.windowSize - The size of s x s window of pixels centered around this pixelThe following example binarizes a TIFF image with Bradley's adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
tiffImage.binarizeBradley(5, 10);
tiffImage.save(dir + "sample.BinarizeBradley5_10x10.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void grayscale()
Convert the image to its grayscale representation, transforming it into a single-channel image where each pixel represents intensity. Integrate this method into your image processing pipeline to simplify analysis and enhance compatibility with grayscale-based algorithms, facilitating various computer vision and image analysis tasks within your application.
grayscale in class RasterCachedMultipageImageThe following example transforms a colored TIFF image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
tiffImage.grayscale();
tiffImage.save(dir + "sample.Grayscale.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void adjustGamma(float gamma)
Apply gamma correction to the image, adjusting pixel intensities to achieve desired color balance. Incorporate this method into your image processing workflow to enhance visual quality and improve the accuracy of subsequent analysis or display tasks within your application.
adjustGamma in class RasterCachedMultipageImagegamma - Gamma for red, green and blue channels coefficientThe following example performs gamma-correction of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Set gamma coefficient for red, green and blue channels.
tiffImage.adjustGamma(2.5f);
tiffImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void adjustGamma(float gammaRed,
float gammaGreen,
float gammaBlue)
Perform gamma correction on the image using individual coefficients for red, green, and blue channels, allowing for fine-tuned adjustments of color balance and contrast. Integrate this method into your image processing pipeline to achieve precise control over color rendering and enhance visual fidelity within your application.
adjustGamma in class RasterCachedMultipageImagegammaRed - Gamma for red channel coefficientgammaGreen - Gamma for green channel coefficientgammaBlue - Gamma for blue channel coefficientThe following example performs gamma-correction of a TIFF image applying different coefficients for color components.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Set individual gamma coefficients for red, green and blue channels.
tiffImage.adjustGamma(1.5f, 2.5f, 3.5f);
tiffImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void adjustBrightness(int brightness)
Implement brightness adjustment for the image, allowing the
modification of overall luminance levels. Incorporate this method into your image
processing workflow to enhance visibility and improve the visual quality of
images within your application.
adjustBrightness in class RasterCachedMultipageImagebrightness - Brightness value.The following example performs brightness correction of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Set the brightness value. The accepted values of brightness are in the range [-255, 255].
tiffImage.adjustBrightness(50);
tiffImage.save(dir + "sample.AdjustBrightness.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void adjustContrast(float contrast)
Enhance the contrast of the Image instance,
amplifying the differences between its light and dark areas. Integrate this
functionality to improve the visual clarity and overall quality of the image
within your application.
adjustContrast in class RasterCachedMultipageImagecontrast - Contrast value (in range [-100; 100])The following example performs contrast correction of a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
tiffImage.adjustContrast(50f);
tiffImage.save(dir + "sample.AdjustContrast.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void filter(Rectangle rectangle, FilterOptionsBase options)
Filter the content within the specified rectangle, applying a designated image processing filter to enhance or modify the selected region. Integrate this method into your image manipulation workflow to achieve targeted enhancements or transformations within your application.
filter in class RasterCachedMultipageImagerectangle - The rectangle.options - The options.The following example applies various types of filters to a TIFF image.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a median filter with a rectangle size of 5 to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5));
tiffImage.save(dir + "sample.MedianFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5));
tiffImage.save(dir + "sample.BilateralSmoothingFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0));
tiffImage.save(dir + "sample.GaussianBlurFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0));
tiffImage.save(dir + "sample.GaussWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0));
tiffImage.save(dir + "sample.MotionWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
image = com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
tiffImage.filter(tiffImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0));
tiffImage.save(dir + "sample.SharpenFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
public void resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Adjust the size of the image based on specified settings, allowing for precise control over dimensions, aspect ratio, and scaling behavior. Integrate this method into your image processing workflow to achieve customized resizing operations tailored to the specific requirements of your application.
resize in class RasterCachedMultipageImagenewWidth - The new width.newHeight - The new height.settings - The resize settings.This example loads a TIFF 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) com.aspose.imaging.Image.load(dir + "sample.tif");
try {
com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = (com.aspose.imaging.fileformats.tiff.TiffImage) image;
// Scale down by 2 times using adaptive resampling.
tiffImage.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings);
// Save to PNG
tiffImage.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
image.dispose();
}
Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.