Packages

 

com.aspose.imaging.fileformats.tiff

Class TiffImage

    • Constructor Detail

      • TiffImage

        public TiffImage(TiffFrame frame)

        Initializes a new instance of the TiffImage class.

        Parameters:
        frame - The tiff frame to initialize image with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - Tiff frame cannot be empty.;frame
        Code example:

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

      • TiffImage

        public TiffImage(TiffFrame[] frames)

        Initializes a new instance of the TiffImage class.

        Parameters:
        frames - The frames.
        Throws:
        com.aspose.ms.System.ArgumentNullException - frames
        Code example:

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

    • Method Detail

      • hasAlpha

        public boolean hasAlpha()

        Gets a value indicating whether this instance has alpha.

        Overrides:
        hasAlpha in class RasterImage
        Returns:
        true if this instance has alpha; otherwise, false.
        Code 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
        

      • hasTransparentColor

        public boolean hasTransparentColor()

        Gets a value indicating whether image has transparent color.

        Overrides:
        hasTransparentColor in class RasterImage
        Returns:
        a value indicating whether image has transparent color.
      • setTransparentColor

        public void setTransparentColor(boolean value)

        Gets a value indicating whether image has transparent color.

        Overrides:
        setTransparentColor in class RasterImage
        Parameters:
        value - a value indicating whether image has transparent color.
      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
        Returns:
        a value of file format
      • getPremultiplyComponents

        public boolean getPremultiplyComponents()

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

        Overrides:
        getPremultiplyComponents in class RasterImage
        Returns:
        true if components must be premultiplied; otherwise, false.
      • setPremultiplyComponents

        public void setPremultiplyComponents(boolean value)

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

        Overrides:
        setPremultiplyComponents in class RasterImage
        Parameters:
        value - true if components must be premultiplied; otherwise, false.
        Code 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:
        The tiff byte order.
      • setByteOrder

        public void setByteOrder(int value)

        Gets or sets a value indicating the tiff byte order.

        Parameters:
        value - The tiff byte order.
      • getHorizontalResolution

        public double getHorizontalResolution()

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

        Overrides:
        getHorizontalResolution in class RasterImage
        Returns:
        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.

        Code 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

        public void setHorizontalResolution(double value)

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

        Overrides:
        setHorizontalResolution in class RasterImage
        Parameters:
        value - 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.

        Overrides:
        getVerticalResolution in class RasterImage
        Returns:
        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.

        Code 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

        public void setVerticalResolution(double value)

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

        Overrides:
        setVerticalResolution in class RasterImage
        Parameters:
        value - 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.

      • getBackgroundColor

        public Color getBackgroundColor()

        Gets or sets a value for the background color.

        Overrides:
        getBackgroundColor in class Image
      • setBackgroundColor

        public void setBackgroundColor(Color value)

        Gets or sets a value for the background color.

        Overrides:
        setBackgroundColor in class Image
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel value of current frame.

        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
      • getActiveFrame

        public TiffFrame getActiveFrame()

        Gets or sets the active frame.

        Returns:
        Active frame.
        Code 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

        public void setActiveFrame(TiffFrame value)

        Gets or sets the active frame.

        Parameters:
        value - Active frame.
        Code 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.

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

      • isCached

        public final boolean isCached()

        Gets a value indicating whether object's data is cached currently and no data reading is required.

        Specified by:
        isCached in class DataStreamSupporter
        Returns:
        true if object's data is cached; otherwise, false.
      • getExifData

        public ExifData getExifData()

        Gets or sets EXIF data for the active frame.

      • setExifData

        public void setExifData(ExifData value)

        Gets or sets EXIF data for the active frame.

      • getImageOpacity

        public float getImageOpacity()

        Gets opacity of this image (active frame).

        Overrides:
        getImageOpacity in class RasterImage
        Returns:
        The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).
      • setXmpData

        public void setXmpData(XmpPacketWrapper value)

        Gets or sets XMP data from frame.

        Overrides:
        setXmpData in class RasterImage
        Parameters:
        value - XMP packet data wrapper
      • alignResolutions

        public void alignResolutions()

        Helper method to make horizontal and vertical resolutions equal.

      • dither

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

        Performs dithering on the current image.

        Specified by:
        dither in class RasterImage
        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        customPalette - The custom palette for dithering.
        Code 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();
        }
        

      • setResolution

        public void setResolution(double dpiX,
                                  double dpiY)

        Sets the resolution for this RasterImage.

        Overrides:
        setResolution in class RasterImage
        Parameters:
        dpiX - The horizontal resolution, in dots per inch, of the RasterImage.
        dpiY - The vertical resolution, in dots per inch, of the RasterImage.
        Code 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
        

      • cacheData

        public final void cacheData()

        Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer.

        Specified by:
        cacheData in class DataStreamSupporter
      • rotateFlip

        public void rotateFlip(int rotateFlipType)

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

        Specified by:
        rotateFlip in class Image
        Parameters:
        rotateFlipType - The rotate flip type.
        Code 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();
            }
        }
        

      • rotateFlipAll

        public void rotateFlipAll(int rotateFlip)

        Rotates the flip all frames in image.

        Parameters:
        rotateFlip - The rotate flip type.
      • rotate

        public void rotate(float angle,
                           boolean resizeProportionally,
                           Color backgroundColor)

        Rotate image around the center.

        Overrides:
        rotate in class RasterImage
        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
        resizeProportionally - 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.
        Code example:

        The following example shows how to rotate a TIFF image around the center by 45 degrees clockwise.


        String dir = "c:\\temp\\";
        com.aspose.imaging.imageoptions.TiffOptions createTiffOptions
                = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
        
        // Create a permanent, not temporary file source.
        createTiffOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dir + "rotated.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 {
            // The linear gradient from the left-top to the right-bottom corner of the image.
            com.aspose.imaging.brushes.LinearGradientBrush brush =
                    new com.aspose.imaging.brushes.LinearGradientBrush(
                            new com.aspose.imaging.Point(0, 0),
                            new com.aspose.imaging.Point(tiffImage.getWidth(), tiffImage.getHeight()),
                            com.aspose.imaging.Color.getRed(),
                            com.aspose.imaging.Color.getGreen());
        
            // Fill the active frame with the linear gradient brush.
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(tiffImage);
            gr.fillRectangle(brush, tiffImage.getBounds());
        
            // Rotate the image around the center by 45 degrees clockwise.
            // The image size changed according to rotated rectangle (corner points).
            tiffImage.rotate(45f, true, com.aspose.imaging.Color.getBlack());
            tiffImage.save();
        
            // Rotate the image around the center by 45 degrees clockwise.
            // Leave the image dimensions untouched and only the internal image content are rotated.
            tiffImage.rotate(45f, false, com.aspose.imaging.Color.getGray());
            tiffImage.save(dir + "rotated.preservesize.tif");
        } finally {
            tiffImage.dispose();
        }
        

      • normalizeAngle

        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.

        Overrides:
        normalizeAngle in class RasterImage
        Parameters:
        resizeProportionally - 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.
      • addFrame

        public void addFrame(TiffFrame frame)

        Adds the frame to image

        Parameters:
        frame - The frame to add.
        Code 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

        public void add(TiffImage image)

        Adds the specified image's frames to current frame.

        Parameters:
        image - The source image.
      • addFrames

        public void addFrames(TiffFrame[] frames)

        Adds the frames array to image

        Parameters:
        frames - The frames array to add
      • insertFrame

        public void insertFrame(int index,
                                TiffFrame frameToInsert)

        The insert frame.

        Parameters:
        index - Index of new frame in list of frames
        frameToInsert - The frame To Insert.
      • replaceFrame

        public final TiffFrame replaceFrame(int index,
                                            TiffFrame frameToReplace)

        Replaces the frame at the specified position.

        Parameters:
        index - The zero based frame position.
        frameToReplace - The frame to replace.


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

        Returns:
        The removed frame.
      • removeFrame

        public TiffFrame removeFrame(int index)

        Removes the frame by its index.

        Parameters:
        index - 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:
        The removed frame.
        Code 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

        public void removeFrame(TiffFrame frame)

        Removes the specified frame.

        Parameters:
        frame - The frame to remove.

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

      • resize

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

        Resizes the image.

        Overrides:
        resize in class RasterImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
        Code example:

        This example loads a TIFF image and resizes it using various resizing methods.


        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.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with 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.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        
            // Save to PNG with 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.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with 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.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
        
            // Save to PNG with default options.
            image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
        } finally {
            image.dispose();
        }
        

      • resize

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

        Resizes the image.

        Overrides:
        resize in class RasterImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        settings - The resize settings.
        Code 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();
        }
        

      • resizeWidthProportionally

        public void resizeWidthProportionally(int newWidth,
                                              int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeWidthProportionally in class Image
        Parameters:
        newWidth - The new width.
        resizeType - Type of the resize.
        Code example:

        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

        public void resizeHeightProportionally(int newHeight,
                                               int resizeType)

        Resizes the height proportionally.

        Overrides:
        resizeHeightProportionally in class Image
        Parameters:
        newHeight - The new height.
        resizeType - Type of the resize.
        Code example:

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

      • resizeProportional

        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:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
      • crop

        public void crop(Rectangle rectangle)

        Cropping the image.

        Overrides:
        crop in class RasterImage
        Parameters:
        rectangle - The rectangle.
        Code example:

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

      • grayscale

        public void grayscale()

        Transformation of an image to its grayscale representation

        Overrides:
        grayscale in class RasterImage
        Code example:

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

      • binarizeFixed

        public void binarizeFixed(byte threshold)

        Binarization of an image with predefined threshold

        Overrides:
        binarizeFixed in class RasterImage
        Parameters:
        threshold - Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
        Code example:

        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

        Overrides:
        binarizeOtsu in class RasterImage
        Code example:

        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

        public void binarizeBradley(double brightnessDifference,
                                    int windowSize)

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

        Overrides:
        binarizeBradley in class RasterImage
        Parameters:
        brightnessDifference - 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 pixel
        Code example:

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

      • crop

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

        Crop image with shifts.

        Overrides:
        crop in class RasterImage
        Parameters:
        leftShift - The left shift.
        rightShift - The right shift.
        topShift - The top shift.
        bottomShift - The bottom shift.
        Code example:

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

      • adjustBrightness

        public void adjustBrightness(int brightness)

        Adjust of a brightness for image.

        Overrides:
        adjustBrightness in class RasterImage
        Parameters:
        brightness - Brightness value.
        Code 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

        public void adjustContrast(float contrast)

        Image contrasting

        Overrides:
        adjustContrast in class RasterImage
        Parameters:
        contrast - Contrast value (in range [-100; 100])
        Code 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();
        }
        

      • adjustGamma

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

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterImage
        Parameters:
        gammaRed - Gamma for red channel coefficient
        gammaGreen - Gamma for green channel coefficient
        gammaBlue - Gamma for blue channel coefficient
        Code 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();
        }
        

      • adjustGamma

        public void adjustGamma(float gamma)

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterImage
        Parameters:
        gamma - Gamma for red, green and blue channels coefficient
        Code 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();
        }
        

      • filter

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Overrides:
        filter in class RasterImage
        Parameters:
        rectangle - The rectangle.
        options - The options.
        Code 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();
        }
        

      • replaceColor

        public void replaceColor(int oldColorArgb,
                                 byte oldColorDiff,
                                 int newColorArgb)

        Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

        Overrides:
        replaceColor in class RasterImage
        Parameters:
        oldColorArgb - Old color ARGB value to be replaced.
        oldColorDiff - Allowed difference in old color to be able to widen replaced color tone.
        newColorArgb - New color ARGB value to replace old color with.
      • replaceNonTransparentColors

        public void replaceNonTransparentColors(int newColorArgb)

        Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.

        Overrides:
        replaceNonTransparentColors in class RasterImage
        Parameters:
        newColorArgb - New color ARGB value to replace non transparent colors with.