edu.northwestern.at.utils.swing
Class JPEGConverters

java.lang.Object
  extended by edu.northwestern.at.utils.swing.JPEGConverters

public class JPEGConverters
extends java.lang.Object

Converts between buffered images and JPEG images stored in byte arrays.


Nested Class Summary
static class JPEGConverters.MyImageWriteParam
           
 
Constructor Summary
JPEGConverters()
           
 
Method Summary
static java.awt.image.BufferedImage fromJPEG(byte[] jpegBytes)
          Convert JPEG stored in byte array to BufferedImage.
static byte[] toJPEG(java.awt.image.BufferedImage image)
          Convert BufferedImage to byte array.
static byte[] toJPEG(java.awt.image.BufferedImage image, float quality)
          Convert BufferedImage to byte array with specified quality.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPEGConverters

public JPEGConverters()
Method Detail

toJPEG

public static byte[] toJPEG(java.awt.image.BufferedImage image)
Convert BufferedImage to byte array.

Parameters:
image - The buffered image to convert to a byte array.

toJPEG

public static byte[] toJPEG(java.awt.image.BufferedImage image,
                            float quality)
Convert BufferedImage to byte array with specified quality.

Parameters:
image - The buffered image to convert to a byte array.
quality - The JPEG encoding quality. Quality must lie in the interval [0.0,1.0].

The quality determines the degree of JPEG compression.

Some guidelines:

  • 0.75 high quality
  • 0.5 medium quality
  • 0.25 low quality

fromJPEG

public static java.awt.image.BufferedImage fromJPEG(byte[] jpegBytes)
Convert JPEG stored in byte array to BufferedImage.

Parameters:
jpegBytes - The image as a byte array.