TiffImage

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image, com.aspose.imaging.RasterImage, com.aspose.imaging.RasterCachedImage, com.aspose.imaging.RasterCachedMultipageImage

All Implemented Interfaces: com.aspose.imaging.IMultipageImageExt

public final class TiffImage extends RasterCachedMultipageImage implements IMultipageImageExt

The tiff image.

Constructors

Constructor Description
TiffImage(TiffFrame frame) Initializes a new instance of the TiffImage class.
TiffImage(TiffFrame[] frames) Initializes a new instance of the TiffImage class.

Methods

Method Description
getFileFormat() Gets a value of file format
getPremultiplyComponents() Gets or sets a value indicating whether components must be premultiplied.
setPremultiplyComponents(boolean value) Gets or sets a value indicating whether components must be premultiplied.
getByteOrder() Gets or sets a value indicating the tiff byte order.
setByteOrder(int value) Gets or sets a value indicating the tiff byte order.
getHorizontalResolution() Gets the horizontal resolution, in pixels per inch, of this Image.
setHorizontalResolution(double value) Gets the horizontal resolution, in pixels per inch, of this Image.
getVerticalResolution() Gets the vertical resolution, in pixels per inch, of this Image.
setVerticalResolution(double value) Gets the vertical resolution, in pixels per inch, of this Image.
getActiveFrame() Gets or sets the active frame.
setActiveFrame(TiffFrame value) Gets or sets the active frame.
getFrames() Gets Frames array of the image.
getExifData() Gets or sets EXIF data for the active frame.
setExifData(ExifData value) Gets or sets EXIF data for the active frame.
getPageCount() Gets the page count.
getPages() Gets the pages.
hasAlpha() Gets the Has alpha channel.
getOriginalOptions() Gets the options based on the original file settings.
addPage(RasterImage page) Adds page to the image.
alignResolutions() Helper method to make horizontal and vertical resolutions equal.
setResolution(double dpiX, double dpiY) Sets the resolution for this RasterImage.
normalizeAngle(boolean resizeProportionally, Color backgroundColor) Normalizes the angle.
addFrame(TiffFrame frame) Adds the frame to image
add(TiffImage image) Adds the specified image’s frames to current frame.
addFrames(TiffFrame[] frames) Adds the frames array to image
insertFrame(int index, TiffFrame frameToInsert) The insert frame.
replaceFrame(int index, TiffFrame frameToReplace) Replaces the frame at the specified position.
removeFrame(int index) Removes the frame by its index.
removeFrame(TiffFrame frame) Removes the specified frame.
resizeProportional(int newWidth, int newHeight, int resizeType) Performs proportional resize on the image.
resizeWidthProportionally(int newWidth, int resizeType) Resizes the width proportionally.
resizeHeightProportionally(int newHeight, int resizeType) Resizes the width proportionally.
rotateFlip(int rotateFlipType) Rotates, flips, or rotates and flips the Active frame only.
dither(int ditheringMethod, int bitsCount, IColorPalette customPalette) Performs dithering on the current image.
crop(Rectangle rectangle) Cropping the image.
crop(int leftShift, int rightShift, int topShift, int bottomShift) Crop image with shifts.
binarizeFixed(byte threshold) Binarization of an image with predefined threshold
binarizeOtsu() Binarization of an image with Otsu thresholding
binarizeBradley(double brightnessDifference, int windowSize) Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
grayscale() Transformation of an image to its grayscale representation
adjustGamma(float gamma) Gamma-correction of an image.
adjustGamma(float gammaRed, float gammaGreen, float gammaBlue) Gamma-correction of an image.
adjustBrightness(int brightness) Adjust of a brightness for image.
adjustContrast(float contrast) Image contrasting
filter(Rectangle rectangle, FilterOptionsBase options) Filters the specified rectangle.
resize(int newWidth, int newHeight, ImageResizeSettings settings) Resizes the image.

Example: 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");
}

Example: Create Path Resources using Graphics Path.

static void main()
{
    try (TiffImage image = (TiffImage)Image.load("Bottle.tif"))
    {
        // Create rectangular Figure for GraphicsPath
        Figure figure = new Figure();
        figure.addShape(createBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));

        // Create GraphicsPath using our Figure
        GraphicsPath graphicsPath = new GraphicsPath();
        graphicsPath.addFigure(figure);

        // Set PathResources using GraphicsPath
        PathResource[] pathResource = PathResourceConverter.fromGraphicsPath(graphicsPath, image.getSize());
        image.getActiveFrame().setPathResources(Arrays.asList(pathResource));

        // Save the image
        image.save("BottleWithRectanglePath.tif");
    }
}

private static BezierShape createBezierShape(float ... coordinates)
{
    PointF[] bezierPoints = coordinatesToBezierPoints(coordinates);
    return new BezierShape(bezierPoints, true);
}

private static PointF[] coordinatesToBezierPoints(float[] coordinates)
{
    PointF[] bezierPoints = new PointF[3 * coordinates.length / 2];
    int i = 0;
    for (int coordinateIndex = 0; coordinateIndex < coordinates.length - 1; coordinateIndex += 2)
        for (int index = 0; index < 3; index++)
        {
            bezierPoints[i++] = new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
        }
                
    return bezierPoints;
}

TiffImage(TiffFrame frame)

public TiffImage(TiffFrame frame)

Initializes a new instance of the TiffImage class.

Parameters:

Parameter Type Description
frame TiffFrame The tiff frame to initialize image with.

TiffImage(TiffFrame[] frames)

public TiffImage(TiffFrame[] frames)

Initializes a new instance of the TiffImage class.

Parameters:

Parameter Type Description
frames TiffFrame[] The frames.

getFileFormat()

public long getFileFormat()

Gets a value of file format

Returns: long - a value of file format

getPremultiplyComponents()

public boolean getPremultiplyComponents()

Gets or sets a value indicating whether components must be premultiplied.

Returns: boolean - true if components must be premultiplied; otherwise, false.

setPremultiplyComponents(boolean value)

public void setPremultiplyComponents(boolean value)

Gets or sets a value indicating whether components must be premultiplied.

Parameters:

Parameter Type Description
value boolean true if components must be premultiplied; otherwise, false.

Example: 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]

getByteOrder()

public int getByteOrder()

Gets or sets a value indicating the tiff byte order.

Returns: int - The tiff byte order.

setByteOrder(int value)

public void setByteOrder(int value)

Gets or sets a value indicating the tiff byte order.

Parameters:

Parameter Type Description
value int The tiff byte order.

getHorizontalResolution()

public double getHorizontalResolution()

Gets the horizontal resolution, in pixels per inch, of this Image.

Returns: double - 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.

Example: 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

setHorizontalResolution(double value)

public void setHorizontalResolution(double value)

Gets the horizontal resolution, in pixels per inch, of this Image.

Parameters:

Parameter Type Description
value double 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. |

getVerticalResolution()

public double getVerticalResolution()

Gets the vertical resolution, in pixels per inch, of this Image.

Returns: double - 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.

Example: 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

setVerticalResolution(double value)

public void setVerticalResolution(double value)

Gets the vertical resolution, in pixels per inch, of this Image.

Parameters:

Parameter Type Description
value double 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. |

getActiveFrame()

public TiffFrame getActiveFrame()

Gets or sets the active frame.

Returns: TiffFrame - Active frame.

Example: 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();
}

setActiveFrame(TiffFrame value)

public void setActiveFrame(TiffFrame value)

Gets or sets the active frame.

Parameters:

Parameter Type Description
value TiffFrame Active frame.

Example: 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();
}

getFrames()

public TiffFrame[] getFrames()

Gets Frames array of the image.

Returns: com.aspose.imaging.fileformats.tiff.TiffFrame[]

Example: 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();
}

getExifData()

public ExifData getExifData()

Gets or sets EXIF data for the active frame.

Returns: ExifData

setExifData(ExifData value)

public void setExifData(ExifData value)

Gets or sets EXIF data for the active frame.

Parameters:

Parameter Type Description
value ExifData

getPageCount()

public int getPageCount()

Gets the page count.

Value: The page count.

Returns: int - the page count.

getPages()

public Image[] getPages()

Gets the pages.

Value: The pages.

Returns: com.aspose.imaging.Image[] - the pages.

hasAlpha()

public boolean hasAlpha()

Gets the Has alpha channel.

Value: The Has alpha channel.

Returns: boolean - the Has alpha channel.

Example: 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

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.

addPage(RasterImage page)

public void addPage(RasterImage page)

Adds page to the image.

Parameters:

Parameter Type Description
page RasterImage The page to add.

alignResolutions()

public void alignResolutions()

Helper method to make horizontal and vertical resolutions equal.

setResolution(double dpiX, double dpiY)

public void setResolution(double dpiX, double dpiY)

Sets the resolution for this RasterImage.

Parameters:

Parameter Type Description
dpiX double The horizontal resolution, in dots per inch, of the RasterImage.
dpiY double The vertical resolution, in dots per inch, of the RasterImage.

Example: 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

normalizeAngle(boolean resizeProportionally, Color backgroundColor)

public void normalizeAngle(boolean resizeProportionally, Color backgroundColor)

Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses RasterImage.getSkewAngle and RasterImage.rotate(float, boolean, Color) methods.

Parameters:

Parameter Type Description
resizeProportionally boolean 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 Color of the background.

addFrame(TiffFrame frame)

public void addFrame(TiffFrame frame)

Adds the frame to image

Parameters:

Parameter Type Description
frame TiffFrame The frame to add.

Example: 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();
}

add(TiffImage image)

public void add(TiffImage image)

Adds the specified image’s frames to current frame.

Parameters:

Parameter Type Description
image TiffImage The source image.

addFrames(TiffFrame[] frames)

public void addFrames(TiffFrame[] frames)

Adds the frames array to image

Parameters:

Parameter Type Description
frames TiffFrame[] The frames array to add

insertFrame(int index, TiffFrame frameToInsert)

public void insertFrame(int index, TiffFrame frameToInsert)

The insert frame.

Parameters:

Parameter Type Description
index int Index of new frame in list of frames
frameToInsert TiffFrame The frame To Insert.

replaceFrame(int index, TiffFrame frameToReplace)

public TiffFrame replaceFrame(int index, TiffFrame frameToReplace)

Replaces the frame at the specified position.

Parameters:

Parameter Type Description
index int The zero based frame position.
frameToReplace TiffFrame The frame to replace.

Note: do not forget to Dispose the frame if you will not add it to some other TiffImage. |

Returns: TiffFrame - The removed frame.

removeFrame(int index)

public TiffFrame removeFrame(int index)

Removes the frame by its index.

Parameters:

Parameter Type Description
index int Index of frame to be removed.

Note: do not forget to Dispose the frame if you will not add it to some other TiffImage. |

Returns: TiffFrame - The removed frame.

Example: 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();
}

removeFrame(TiffFrame frame)

public void removeFrame(TiffFrame frame)

Removes the specified frame.

Parameters:

Parameter Type Description
frame TiffFrame The frame to remove.

Note: do not forget to Dispose the frame if you will not add it to some other TiffImage. |

resizeProportional(int newWidth, int newHeight, int resizeType)

public void resizeProportional(int newWidth, int newHeight, int resizeType)

Performs proportional resize on the image. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.

Parameters:

Parameter Type Description
newWidth int The new width.
newHeight int The new height.
resizeType int The resize type.

resizeWidthProportionally(int newWidth, int resizeType)

public void resizeWidthProportionally(int newWidth, int resizeType)

Resizes the width proportionally.

Parameters:

Parameter Type Description
newWidth int The new width.
resizeType int Type of the resize.

Example: This example loads a TIFF image and resizes it proportionally using various resizing methods. This 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();
}

resizeHeightProportionally(int newHeight, int resizeType)

public void resizeHeightProportionally(int newHeight, int resizeType)

Resizes the width proportionally.

Parameters:

Parameter Type Description
newHeight int The new height.
resizeType int Type of the resize.

Example: This example loads a TIFF image and resizes it proportionally using various resizing methods. This 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();
}

rotateFlip(int rotateFlipType)

public void rotateFlip(int rotateFlipType)

Rotates, flips, or rotates and flips the Active frame only.

Parameters:

Parameter Type Description
rotateFlipType int The rotation and flipping type.

Example: This 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();
    }
}

dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

public void dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

Performs dithering on the current image.

Parameters:

Parameter Type Description
ditheringMethod int The dithering method.
bitsCount int The final bits count for dithering.
customPalette IColorPalette The custom palette for dithering.

Example: The 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();
}

crop(Rectangle rectangle)

public void crop(Rectangle rectangle)

Cropping the image.

Parameters:

Parameter Type Description
rectangle Rectangle The rectangle.

Example: The following example crops a TIFF image. 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();
}

crop(int leftShift, int rightShift, int topShift, int bottomShift)

public void crop(int leftShift, int rightShift, int topShift, int bottomShift)

Crop image with shifts.

Parameters:

Parameter Type Description
leftShift int The left shift.
rightShift int The right shift.
topShift int The top shift.
bottomShift int The bottom shift.

Example: The following example crops a TIFF image. 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();
}

binarizeFixed(byte threshold)

public void binarizeFixed(byte threshold)

Binarization of an image with predefined threshold

Parameters:

Parameter Type Description
threshold byte Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.

Example: The following example binarizes a TIFF image with the predefined threshold. 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();
}

binarizeOtsu()

public void binarizeOtsu()

Binarization of an image with Otsu thresholding

Example: The following example binarizes a TIFF image with Otsu thresholding. The 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();
}

binarizeBradley(double brightnessDifference, int windowSize)

public void binarizeBradley(double brightnessDifference, int windowSize)

Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding

Parameters:

Parameter Type Description
brightnessDifference double The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
windowSize int The size of s x s window of pixels centered around this pixel

Example: The following example binarizes a TIFF image with Bradley’s adaptive thresholding algorithm with the specified window size. The 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();
}

grayscale()

public void grayscale()

Transformation of an image to its grayscale representation

Example: The following example transforms a colored TIFF image to its grayscale representation. The 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();
}

adjustGamma(float gamma)

public void adjustGamma(float gamma)

Gamma-correction of an image.

Parameters:

Parameter Type Description
gamma float Gamma for red, green and blue channels coefficient

Example: The 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();
}

adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

public void adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

Gamma-correction of an image.

Parameters:

Parameter Type Description
gammaRed float Gamma for red channel coefficient
gammaGreen float Gamma for green channel coefficient
gammaBlue float Gamma for blue channel coefficient

Example: The 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();
}

adjustBrightness(int brightness)

public void adjustBrightness(int brightness)

Adjust of a brightness for image.

Parameters:

Parameter Type Description
brightness int Brightness value.

Example: 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();
}

adjustContrast(float contrast)

public void adjustContrast(float contrast)

Image contrasting

Parameters:

Parameter Type Description
contrast float Contrast value (in range [-100; 100])

Example: 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();
}

filter(Rectangle rectangle, FilterOptionsBase options)

public void filter(Rectangle rectangle, FilterOptionsBase options)

Filters the specified rectangle.

Parameters:

Parameter Type Description
rectangle Rectangle The rectangle.
options FilterOptionsBase The options.

Example: 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();
}

resize(int newWidth, int newHeight, ImageResizeSettings settings)

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

Resizes the image.

Parameters:

Parameter Type Description
newWidth int The new width.
newHeight int The new height.
settings ImageResizeSettings The resize settings.

Example: 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();
}