ucar.unidata.ui
Class ImageUtils

java.lang.Object
  extended by ucar.unidata.ui.ImageUtils

public class ImageUtils
extends Object

Provides a set of image manipulation utilities

Author:
IDV development team

Field Summary
static boolean debug
          debug flag
 
Constructor Summary
ImageUtils()
           
 
Method Summary
static BufferedImage clip(BufferedImage image, int[] ul, int[] lr)
          Clip the image
static String convertImageTo(String file, String newType)
          Convert an image to a new type
static JEditorPane getEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font)
          _more_
static JEditorPane getEditor(String html, int width, Color transparentColor, Font font)
          _more_
static Image getImage(Component component)
          Get the screen image from the component
static Image getImage(JEditorPane editor, Color transparentColor)
          _more_
static Image getImageFile(String file)
          Read in the image from the given filename or url
static Image gridImages(List images, int space, Color bg, int columns)
          Merge images
static boolean hasAlpha(Image image)
          Check to see if the image has alpha
static boolean isImage(String file)
           
static void main(String[] args)
          Read in the image.
static BufferedImage makeColorTransparent(Image im, Color c)
          Make a color in the image transparent
static BufferedImage makeColorTransparent(Image im, int[] redRange, int[] greenRange, int[] blueRange)
          Set the colors taht are within the given red, green and blue ranges to be transparent.
static BufferedImage matte(BufferedImage image, int top, int bottom, int left, int right, Color bg)
          Add a matte border around the image
static Image mergeImages(List images, int space, Color bg)
          Merge images
static Point parsePoint(String s, Rectangle r)
          Parse the string specification of a point with respect to the rectangle.
static Image readImage(String imagePath)
          Read and image
static Image renderHtml(String html, int width, Color transparentColor, Font font)
          _more_
static Image resize(Image image, int width, int height)
          Resize an image
static BufferedImage toBufferedImage(Image image)
          This method returns a buffered image with the contents of an image
static BufferedImage toBufferedImage(Image image, int type)
          Create a BufferedImage from the given image
static Point toPoint(Point2D p)
          convenience to convert to a Point
static Image waitOnImage(Image image)
          Wait until it is loaded in.
static void writeAvi(List imageFiles, double frameRateInFPS, File outFile)
          Write an AVI file
static boolean writeImage(JDialog window, String file)
          Make a screen capture of the window.
static boolean writeImage(JFrame window, String file)
          Make a screen capture of the window.
static void writeImageToFile(Component component, String saveFile)
          Take a screen snapshot of the component.
static void writeImageToFile(Image image, String saveFile)
          Write a Buffered image to a file
static void writeImageToFile(Image image, String saveFile, float quality)
          Write a Buffered image to a file at a particular quality
static void writeImageToFile(Image image, String saveFile, OutputStream os, float quality)
           
static void writePDF(OutputStream out, JComponent comp)
          _more_
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
debug flag

Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

matte

public static BufferedImage matte(BufferedImage image,
                                  int top,
                                  int bottom,
                                  int left,
                                  int right,
                                  Color bg)
Add a matte border around the image

Parameters:
image - The image
top - top space
bottom - bottom space
left - left space
right - right space
bg - Background color
Returns:
The matted image

clip

public static BufferedImage clip(BufferedImage image,
                                 int[] ul,
                                 int[] lr)
Clip the image

Parameters:
image - The image
ul - upper left
lr - lower right
Returns:
The clipped image

readImage

public static Image readImage(String imagePath)
Read and image

Parameters:
imagePath - the path to the image
Returns:
the Image

waitOnImage

public static Image waitOnImage(Image image)
Wait until it is loaded in.

Parameters:
image - the image
Returns:
The image

makeColorTransparent

public static BufferedImage makeColorTransparent(Image im,
                                                 Color c)
Make a color in the image transparent

Parameters:
im - image
c - the color to make transparent
Returns:
a new image with the color transparent.

makeColorTransparent

public static BufferedImage makeColorTransparent(Image im,
                                                 int[] redRange,
                                                 int[] greenRange,
                                                 int[] blueRange)
Set the colors taht are within the given red, green and blue ranges to be transparent.

Parameters:
im - The image
redRange - red range
greenRange - green range
blueRange - blue range
Returns:
munged image

toPoint

public static Point toPoint(Point2D p)
convenience to convert to a Point

Parameters:
p - point
Returns:
point

parsePoint

public static Point parsePoint(String s,
                               Rectangle r)
Parse the string specification of a point with respect to the rectangle. The spec can look like: "rectpoint,offsetx,offsety" where rectpoint can be:
 ul    um    ur
 ml    mm    mr
 ll    lm    lr
Where u=upper,m=middle,l=lower r=right,l=left

Parameters:
s - Stirng spec
r - Reference rect
Returns:
The point

toBufferedImage

public static BufferedImage toBufferedImage(Image image)
This method returns a buffered image with the contents of an image

Parameters:
image - the image
Returns:
a buffered image

mergeImages

public static Image mergeImages(List images,
                                int space,
                                Color bg)
Merge images

Parameters:
images - list of images
space - space between images
bg - background color
Returns:
merged image

gridImages

public static Image gridImages(List images,
                               int space,
                               Color bg,
                               int columns)
Merge images

Parameters:
images - list of images
space - space between images
bg - background color
Returns:
merged image

toBufferedImage

public static BufferedImage toBufferedImage(Image image,
                                            int type)
Create a BufferedImage from the given image

Parameters:
image - The image
type - BufferedImage type
Returns:
The BufferedImage

hasAlpha

public static boolean hasAlpha(Image image)
Check to see if the image has alpha

Parameters:
image - the image
Returns:
true if has alpha

getImage

public static Image getImage(Component component)
                      throws Exception
Get the screen image from the component

Parameters:
component - The component.
Returns:
Its image
Throws:
Exception

writeImageToFile

public static void writeImageToFile(Image image,
                                    String saveFile)
                             throws Exception
Write a Buffered image to a file

Parameters:
image - image to write
saveFile - file to write to
Throws:
Exception - problem writing file

convertImageTo

public static String convertImageTo(String file,
                                    String newType)
Convert an image to a new type

Parameters:
file - image file
newType - new image type
Returns:
name of the new file

writeImageToFile

public static void writeImageToFile(Image image,
                                    String saveFile,
                                    float quality)
                             throws Exception
Write a Buffered image to a file at a particular quality

Parameters:
image - image to write
saveFile - file to write to
quality - image quality (if supported)
Throws:
Exception - problem writing file

writeImageToFile

public static void writeImageToFile(Image image,
                                    String saveFile,
                                    OutputStream os,
                                    float quality)
                             throws Exception
Throws:
Exception

isImage

public static boolean isImage(String file)

writeImage

public static boolean writeImage(JDialog window,
                                 String file)
                          throws Exception
Make a screen capture of the window. Write it to the file.

Parameters:
window - The window
file - The file
Returns:
Successful
Throws:
Exception

writeImage

public static boolean writeImage(JFrame window,
                                 String file)
                          throws Exception
Make a screen capture of the window. Write it to the file.

Parameters:
window - The window
file - The file
Returns:
Successful
Throws:
Exception

writeImageToFile

public static void writeImageToFile(Component component,
                                    String saveFile)
                             throws Exception
Take a screen snapshot of the component. Write it to the file.

Parameters:
component - The component.
saveFile - The file.
Throws:
Exception

writeAvi

public static void writeAvi(List imageFiles,
                            double frameRateInFPS,
                            File outFile)
                     throws IOException
Write an AVI file

Parameters:
imageFiles - list of files
frameRateInFPS - frame rate
outFile - output file
Throws:
IOException - problem writing AVI

resize

public static Image resize(Image image,
                           int width,
                           int height)
Resize an image

Parameters:
image - the image
width - new width
height - new height
Returns:
resized image

getImage

public static Image getImage(JEditorPane editor,
                             Color transparentColor)
                      throws Exception
_more_

Parameters:
editor - _more_
transparentColor - _more_
Returns:
_more_
Throws:
Exception - _more_

renderHtml

public static Image renderHtml(String html,
                               int width,
                               Color transparentColor,
                               Font font)
                        throws Exception
_more_

Parameters:
html - _more_
width - _more_
transparentColor - _more_
font - _more_
Returns:
_more_
Throws:
Exception - _more_

getEditor

public static JEditorPane getEditor(String html,
                                    int width,
                                    Color transparentColor,
                                    Font font)
                             throws Exception
_more_

Parameters:
html - _more_
width - _more_
transparentColor - _more_
font - _more_
Returns:
_more_
Throws:
Exception - _more_

getEditor

public static JEditorPane getEditor(JEditorPane editor,
                                    String html,
                                    int width,
                                    Color transparentColor,
                                    Font font)
                             throws Exception
_more_

Parameters:
editor - _more_
html - _more_
width - _more_
transparentColor - _more_
font - _more_
Returns:
_more_
Throws:
Exception - _more_

writePDF

public static void writePDF(OutputStream out,
                            JComponent comp)
                     throws IOException
_more_

Parameters:
out - _more_
comp - _more_
Throws:
IOException - _more_

main

public static void main(String[] args)
                 throws Exception
Read in the image. Wait util it is loaded in.

Parameters:
args - args
Throws:
Exception - problem with this

getImageFile

public static Image getImageFile(String file)
                          throws Exception
Read in the image from the given filename or url

Parameters:
file - File or url
Returns:
The image
Throws:
Exception - On badness