Class TiffEncoder

java.lang.Object
com.idrsolutions.image.JDeliImage
com.idrsolutions.image.tiff.TiffEncoder
All Implemented Interfaces:
com.idrsolutions.image.Encoder

public class TiffEncoder extends com.idrsolutions.image.JDeliImage implements com.idrsolutions.image.Encoder
Class writes BufferedImages as Tiff

Example 1 (single-page tiff):


 TiffEncoder encoder = new TiffEncoder();
 encoder.getEncoderOptions().setCompressionFormat(TiffCompressionFormat.DEFLATE); //default is NONE
 encoder.write(image, bos);
 

Example 2 (multi-page tiff)


 TiffEncoder encoder = new TiffEncoder();
 for (BufferedImage image : yourImageArray) {
     encoder.append(image, fileName);
 }
 
  • Constructor Details

    • TiffEncoder

      public TiffEncoder(TiffEncoderOptions tiffOptions)
    • TiffEncoder

      public TiffEncoder()
  • Method Details

    • write

      public void write(BufferedImage image, OutputStream outputStream) throws IOException
      Writes BufferedImage as Tiff to OutputStream

      This method does not close the provided OutputStream after the write operation has completed; it is the responsibility of the caller to close the stream.

      Specified by:
      write in interface com.idrsolutions.image.Encoder
      Parameters:
      image - BufferedImage The image to write
      outputStream - The stream to write to
      Throws:
      IOException - if the image wasn't written
    • append

      public void append(BufferedImage image, String fileName) throws IOException
      Appends image to specified tiff file

      If the file is empty then this method will write the image to the file, otherwise it will append the image after previous image.

      Parameters:
      image - BufferedImage The image to append
      fileName - The name of the file where the image will be written
      Throws:
      IOException - if the file is unreadable
    • append

      public byte[] append(BufferedImage image, byte[] out) throws IOException
      Appends image to byte array

      If the array is empty then this method will write the image, otherwise it will append the image after previous image.

      Parameters:
      image - BufferedImage The image to append
      out - The byte array where the image will be written
      Throws:
      IOException
    • isCompressed

      @Deprecated public boolean isCompressed()
      Deprecated.
      use
      
                       getEncoderOptions().getCompressionFormat().equals(TiffCompressionFormat.DEFLATE);
                   
      Returns whether Deflate compression is enabled in tiff generation.
      Returns:
      Whether compression is enabled
    • getEncoderOptions

      public TiffEncoderOptions getEncoderOptions()
      Specified by:
      getEncoderOptions in interface com.idrsolutions.image.Encoder
    • setEncoderOptions

      public void setEncoderOptions(TiffEncoderOptions tiffEncoderOptions)
    • setCompressed

      @Deprecated public void setCompressed(boolean compress)
      Deprecated.
      use
      
                       tiffEncoderOptions.setCompressionFormat(TiffCompressionFormat tiffCompression);
                       setEncoderOptions(tiffEncoderOptions);
                   
      Parameters:
      compress - value to determine if compression used
    • setXMPMetaData

      @Deprecated public void setXMPMetaData(String xmpMetaData)
      Deprecated.
      use
      
                       tiffEncoderOptions.setXmpMetaData("string");
                       setEncoderOptions(tiffEncoderOptions);
                   
      set XMP MetaData to be written on images;
      Parameters:
      xmpMetaData - header data for Tiff file