org.xenbase.utilities
Class AdvImageUtil

java.lang.Object
  extended by org.xenbase.utilities.AdvImageUtil

public class AdvImageUtil
extends java.lang.Object


Constructor Summary
AdvImageUtil()
           
 
Method Summary
static java.awt.image.RenderedImage convertImageByteArrayToRenderedImage(byte[] b)
          Takes a raw byte array and converts it into a JAI RenderedImage that can be used for manipulation (i.e.
static byte[] convertTo(java.lang.String toFormat, byte[] imgBytes)
          Converts images to a limited variety of formats.
static java.lang.String getFileType(byte[] imgBytes)
          Determine the image encoding format of the image contained within the passed byte array
static int getHeight(byte[] imgBytes)
          Determines the height of an image.
static int getWidth(byte[] imgBytes)
          Determines the width of an image.
static byte[] makeImageByteArrayFromRenderedImage(java.awt.image.RenderedImage image)
          Converts a JAI rendered image to a byte array image
static byte[] scaleTo(int x, int y, byte[] imgBytes)
          Scales an image to the exact height and width provided, please note, this process will not preserve the aspect ratio of the image.
static byte[] scaleToFit(int width, int height, byte[] imgBytes)
          Scales an image to fit the dimensions provided.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdvImageUtil

public AdvImageUtil()
Method Detail

convertTo

public static byte[] convertTo(java.lang.String toFormat,
                               byte[] imgBytes)
                        throws java.lang.Exception,
                               java.lang.Error
Converts images to a limited variety of formats.

Parameters:
toFormat - a string denoting the format you want to convert to 'jpg', 'jpeg', 'png', 'tif', tiff'
imgBytes - the byte array containing the image you want to convert
Returns:
byte array of the newly converted image
Throws:
java.lang.Exception
java.lang.Error

getFileType

public static java.lang.String getFileType(byte[] imgBytes)
                                    throws java.lang.Exception,
                                           java.lang.Error
Determine the image encoding format of the image contained within the passed byte array

Parameters:
imgBytes - byte array of the image you want to identify.
Returns:
string containing the file type of the image in question
Throws:
java.lang.Exception
java.lang.Error

getHeight

public static int getHeight(byte[] imgBytes)
                     throws java.lang.Exception,
                            java.lang.Error
Determines the height of an image.

Parameters:
imgBytes - image byte array
Returns:
int with the height of the image
Throws:
java.lang.Exception
java.lang.Error

getWidth

public static int getWidth(byte[] imgBytes)
                    throws java.lang.Exception,
                           java.lang.Error
Determines the width of an image.

Parameters:
imgBytes - image byte array
Returns:
int with the width of the image
Throws:
java.lang.Exception
java.lang.Error

scaleTo

public static byte[] scaleTo(int x,
                             int y,
                             byte[] imgBytes)
                      throws java.lang.Exception,
                             java.lang.Error
Scales an image to the exact height and width provided, please note, this process will not preserve the aspect ratio of the image. If you wish to preserve the aspect ratio use scaleToFit.

Parameters:
x - int the width you want the resulting image to be.
y - int the height you want the resulting image to be
imgBytes - the byte array of the image you want to scale
Returns:
the byte array of the scaled image
Throws:
java.lang.Exception
java.lang.Error

scaleToFit

public static byte[] scaleToFit(int width,
                                int height,
                                byte[] imgBytes)
                         throws java.lang.Exception,
                                java.lang.Error
Scales an image to fit the dimensions provided. Aspect ratio is maintained therefore it is possible that one of the dimensions of the image will be less than the maximum size you specified.

Parameters:
width - the maximum width to scale the image to
height - the maximum height to scale the image to
imgBytes - the byte array containing the image
Returns:
byte array with the scaled image
Throws:
java.lang.Exception
java.lang.Error

makeImageByteArrayFromRenderedImage

public static byte[] makeImageByteArrayFromRenderedImage(java.awt.image.RenderedImage image)
                                                  throws java.lang.Exception,
                                                         java.lang.Error
Converts a JAI rendered image to a byte array image

Parameters:
image - JAI Rendered Image
Returns:
byte array of the image in JPEG format
Throws:
java.lang.Exception
java.lang.Error

convertImageByteArrayToRenderedImage

public static java.awt.image.RenderedImage convertImageByteArrayToRenderedImage(byte[] b)
                                                                         throws java.lang.Exception,
                                                                                java.lang.Error
Takes a raw byte array and converts it into a JAI RenderedImage that can be used for manipulation (i.e. resizing).

Parameters:
byte[] - b
Returns:
RenderedImage
Throws:
java.lang.Exception
java.lang.Error