Class JpegEncoder

  • All Implemented Interfaces:
    com.idrsolutions.image.Encoder

    public class JpegEncoder
    extends com.idrsolutions.image.JDeliImage
    implements com.idrsolutions.image.Encoder
    Class writes BufferedImages as Baseline JPEGs

    Example:

    
     JpegEncoder encoder = new JpegEncoder();
     //encoder.setQuality(75);
     encoder.write(bufferedImage, outputStream);
     
    • Constructor Detail

      • JpegEncoder

        public JpegEncoder()
    • Method Detail

      • write

        public void write​(BufferedImage image,
                          OutputStream out)
                   throws IOException
        Writes BufferedImage as Baseline JPEG to an 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
        out - The stream to write to
        Throws:
        IOException - if the image wasn't written
      • setQuality

        public void setQuality​(int quality)
        Set the image quality level for JPEG output. The quality level can be between 1 - 100 and if not set defaults to 50. Higher quality produces better quality JPEG files but increases output data size.
        Parameters:
        quality - Quality level to set for JPEG output
      • getQuality

        public int getQuality()
        Retrieve the image quality level for JPEG output. The quality level can be between 1 - 100 and if not set defaults to 50. Higher quality produces better quality JPEG files but increases output data size.
        Returns:
        Quality level used for JPEG output