Module platform

Class EncoderUtil

java.lang.Object
org.jfree.chart.encoders.EncoderUtil

public class EncoderUtil extends Object
A collection of utility methods for encoding images and returning them as a byte[] or writing them directly to an OutputStream.
  • Constructor Details

    • EncoderUtil

      public EncoderUtil()
  • Method Details

    • encode

      public static byte[] encode(BufferedImage image, String format) throws IOException
      Encode the image in a specific format.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      Returns:
      The byte[] that is the encoded image.
      Throws:
      IOException - if there is an IO problem.
    • encode

      public static byte[] encode(BufferedImage image, String format, boolean encodeAlpha) throws IOException
      Encode the image in a specific format.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      encodeAlpha - Whether to encode alpha transparency (not supported by all ImageEncoders).
      Returns:
      The byte[] that is the encoded image.
      Throws:
      IOException - if there is an IO problem.
    • encode

      public static byte[] encode(BufferedImage image, String format, float quality) throws IOException
      Encode the image in a specific format.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      quality - The quality to use for the image encoding (not supported by all ImageEncoders).
      Returns:
      The byte[] that is the encoded image.
      Throws:
      IOException - if there is an IO problem.
    • encode

      public static byte[] encode(BufferedImage image, String format, float quality, boolean encodeAlpha) throws IOException
      Encode the image in a specific format.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      quality - The quality to use for the image encoding (not supported by all ImageEncoders).
      encodeAlpha - Whether to encode alpha transparency (not supported by all ImageEncoders).
      Returns:
      The byte[] that is the encoded image.
      Throws:
      IOException - if there is an IO problem.
    • writeBufferedImage

      public static void writeBufferedImage(BufferedImage image, String format, OutputStream outputStream) throws IOException
      Encode the image in a specific format and write it to an OutputStream.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      outputStream - The OutputStream to write the encoded image to.
      Throws:
      IOException - if there is an IO problem.
    • writeBufferedImage

      public static void writeBufferedImage(BufferedImage image, String format, OutputStream outputStream, float quality) throws IOException
      Encode the image in a specific format and write it to an OutputStream.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      outputStream - The OutputStream to write the encoded image to.
      quality - The quality to use for the image encoding (not supported by all ImageEncoders).
      Throws:
      IOException - if there is an IO problem.
    • writeBufferedImage

      public static void writeBufferedImage(BufferedImage image, String format, OutputStream outputStream, boolean encodeAlpha) throws IOException
      Encode the image in a specific format and write it to an OutputStream.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      outputStream - The OutputStream to write the encoded image to.
      encodeAlpha - Whether to encode alpha transparency (not supported by all ImageEncoders).
      Throws:
      IOException - if there is an IO problem.
    • writeBufferedImage

      public static void writeBufferedImage(BufferedImage image, String format, OutputStream outputStream, float quality, boolean encodeAlpha) throws IOException
      Encode the image in a specific format and write it to an OutputStream.
      Parameters:
      image - The image to be encoded.
      format - The ImageFormat to use.
      outputStream - The OutputStream to write the encoded image to.
      quality - The quality to use for the image encoding (not supported by all ImageEncoders).
      encodeAlpha - Whether to encode alpha transparency (not supported by all ImageEncoders).
      Throws:
      IOException - if there is an IO problem.