portaview.util
Class ImageUtils

java.lang.Object
  extended byportaview.util.ImageUtils

public class ImageUtils
extends java.lang.Object

Image utilities to process JPG images.

Version:
$Id: ImageUtils.java,v 1.9 2003/12/10 06:18:56 wlee Exp $
Author:
William Lee

Constructor Summary
ImageUtils()
           
 
Method Summary
static void drawBorder(java.awt.Graphics2D g, float trans, int bwidth, int maxWidth, int maxHeight, java.awt.Color c)
          Draws border around the graphics
static void drawBorder(java.awt.Graphics2D g, float trans, int bwidth, int xoffset, int yoffset, int maxWidth, int maxHeight, java.awt.Color c)
          Draws border around the graphics
static void drawBorder(PortaViewModel pvm, java.awt.image.BufferedImage bi)
          Draw the image according to the specified settings.
static void drawBorderRatio(java.awt.Graphics2D g, float trans, int ratio, int maxWidth, int maxHeight, java.awt.Color c)
          Draws border around the graphics with the width expressed as a ratio to the whole image.
static void drawBorderRatio(java.awt.Graphics2D g, float trans, int ratio, int xoffset, int yoffset, int maxWidth, int maxHeight, java.awt.Color c)
          Draws border around the graphics with the width expressed as a ratio to the whole image.
static java.awt.image.BufferedImage getBufferedImage(java.io.File file, java.awt.Component c)
          Returns a buffered image based on the file an component to draw on.
static java.awt.image.BufferedImage getBufferedImage(java.awt.Image img, java.awt.Component c)
          Similar to getBufferedImage(File, Component), load the BufferedImage from an Image.
static java.awt.image.BufferedImage getBufferedImageInFrame(java.awt.image.BufferedImage bi, int fwidth, int fheight, java.awt.Component c)
          Returns a buffered image, resized to fit the frame specified by fwidth and fheight.
static java.awt.image.BufferedImage getBufferedImageInFrame(java.io.File f, int fwidth, int fheight, java.awt.Component c)
          Returns a buffered image, resized to fit the frame specified by fwidth and fheight.
static java.awt.Image getImage(byte[] bytes)
          Returns the image given the JPEG encoding in a byte array.
static java.awt.Image getImage(java.io.File file)
          Similar to getImage(String), load from a File instead of the file name.
static java.awt.Image getImage(java.lang.String filename)
          Similar to getImage(URL), load from a filename instead of the URL.
static java.awt.Image getImage(java.net.URL url)
          Returns the image associated with the url
static byte[] getScaledImage(java.io.File f, int width, int height)
          Returns the JPEG encoding of a scaled image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

getImage

public static java.awt.Image getImage(java.net.URL url)
                               throws java.lang.Exception
Returns the image associated with the url

Parameters:
url - url to get the image
Returns:
the Image
Throws:
java.lang.Exception - when getting the image fails.

getImage

public static java.awt.Image getImage(java.lang.String filename)
                               throws java.lang.Exception
Similar to getImage(URL), load from a filename instead of the URL.

Throws:
java.lang.Exception

getImage

public static java.awt.Image getImage(java.io.File file)
                               throws java.lang.Exception
Similar to getImage(String), load from a File instead of the file name.

Throws:
java.lang.Exception

getImage

public static java.awt.Image getImage(byte[] bytes)
Returns the image given the JPEG encoding in a byte array.

Parameters:
bytes - byte array that contains the JPEG encoding of the image.
Returns:
the Image object.

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.io.File file,
                                                            java.awt.Component c)
                                                     throws java.lang.Exception
Returns a buffered image based on the file an component to draw on.

Parameters:
file - file to retrieve
c - component to draw on
Returns:
the BufferedImage object
Throws:
java.lang.Exception - when loading of the image fails.

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.awt.Image img,
                                                            java.awt.Component c)
                                                     throws java.lang.Exception
Similar to getBufferedImage(File, Component), load the BufferedImage from an Image.

Parameters:
img - image to load
c - component to draw on
Returns:
the BufferedImage object
Throws:
java.lang.Exception - when fails to load.

getBufferedImageInFrame

public static java.awt.image.BufferedImage getBufferedImageInFrame(java.awt.image.BufferedImage bi,
                                                                   int fwidth,
                                                                   int fheight,
                                                                   java.awt.Component c)
                                                            throws java.lang.Exception
Returns a buffered image, resized to fit the frame specified by fwidth and fheight. Note that this will maintain the image's ratio.

Parameters:
bi - Buffered image that contains the source for the image.
fwidth - frame width
fheight - height
c - component to draw the image from.
Returns:
A new instance of BufferedImage
Throws:
java.lang.Exception

getBufferedImageInFrame

public static java.awt.image.BufferedImage getBufferedImageInFrame(java.io.File f,
                                                                   int fwidth,
                                                                   int fheight,
                                                                   java.awt.Component c)
                                                            throws java.lang.Exception
Returns a buffered image, resized to fit the frame specified by fwidth and fheight. Note that this will maintain the image's ratio.

Parameters:
f - file to load the image from
fwidth - frame width
fheight - height
c - component to draw the image from.
Returns:
A new instance of BufferedImage
Throws:
java.lang.Exception

getScaledImage

public static byte[] getScaledImage(java.io.File f,
                                    int width,
                                    int height)
                             throws java.lang.Exception
Returns the JPEG encoding of a scaled image.

Parameters:
f - image file.
width - desired width for the image
height - desired height for image
Returns:
the JPEG encoding of the scaled image.
Throws:
java.lang.Exception - when scaling fails.

drawBorderRatio

public static void drawBorderRatio(java.awt.Graphics2D g,
                                   float trans,
                                   int ratio,
                                   int maxWidth,
                                   int maxHeight,
                                   java.awt.Color c)
Draws border around the graphics with the width expressed as a ratio to the whole image.

Parameters:
g - graphic to draw on
ratio - goes from 0 to 30, which means the % of the picture.
maxWidth - maximum width of graphics
maxHeight - maximum height of graphics
c - the color of the border

drawBorderRatio

public static void drawBorderRatio(java.awt.Graphics2D g,
                                   float trans,
                                   int ratio,
                                   int xoffset,
                                   int yoffset,
                                   int maxWidth,
                                   int maxHeight,
                                   java.awt.Color c)
Draws border around the graphics with the width expressed as a ratio to the whole image.

Parameters:
g - graphic to draw on
ratio - goes from 0 to 30, which means the % of the picture.
xoffset - the x coordinate offset
yoffset - the y coordinate offset
maxWidth - maximum width of graphics
maxHeight - maximum height of graphics
c - the color of the border

drawBorder

public static void drawBorder(java.awt.Graphics2D g,
                              float trans,
                              int bwidth,
                              int xoffset,
                              int yoffset,
                              int maxWidth,
                              int maxHeight,
                              java.awt.Color c)
Draws border around the graphics

Parameters:
g - graphic to draw on
bwidth - border width
xoffset - the x coordinate offset
yoffset - the y coordinate offset
maxWidth - maximum width of graphics
maxHeight - maximum height of graphics
c - the color of the border

drawBorder

public static void drawBorder(java.awt.Graphics2D g,
                              float trans,
                              int bwidth,
                              int maxWidth,
                              int maxHeight,
                              java.awt.Color c)
Draws border around the graphics

Parameters:
g - graphic to draw on
bwidth - border width
maxWidth - maximum width of graphics
maxHeight - maximum height of graphics
c - the color of the border

drawBorder

public static void drawBorder(PortaViewModel pvm,
                              java.awt.image.BufferedImage bi)
Draw the image according to the specified settings.

Parameters:
pvm -
bi -


Copyright © 2003 The PortaView Team. All Rights Reserved.