edu.stanford.hci.r3.util.graphics
Class ImageUtils

java.lang.Object
  extended by edu.stanford.hci.r3.util.graphics.ImageUtils

public class ImageUtils
extends java.lang.Object

This software is distributed under the BSD License.


Constructor Summary
ImageUtils()
           
 
Method Summary
static java.awt.image.BufferedImage createWritableBuffer(int width, int height)
           
static long getTimeFromString(java.lang.String timestampString)
          Parses strings like 2005:03:30 19:20:23 and returns a java.sql.Timestamp object.
static boolean isJPEGFile(java.io.File imageFile)
           
static java.lang.String readCaptureDateFromEXIF(java.io.File photoFile)
          Gets the EXIF timestamp from a photo.
static java.awt.image.BufferedImage readImage(java.io.File source)
           
static java.awt.Dimension readSize(java.io.File imageFile)
          This works for both JPEG and non JPEG images/photos.
static java.awt.Dimension readSizeByLoading(java.io.File imageFile)
          Load in the image file just to read the photo size...
static long readTimeFrom(java.io.File photo)
          If the EXIF field does not exist, it will return a time representing the file last modified date/time.
static java.awt.image.BufferedImage scaleImage(java.awt.image.BufferedImage src, float sX, float sY)
          Scaled a buffered image by the two scale parameters.
static java.awt.image.BufferedImage scaleImageToFit(java.awt.image.BufferedImage src, int width, int height)
           
static java.awt.image.BufferedImage scaleImageToSize(java.awt.image.BufferedImage src, int targetWidth, int targetHeight, boolean maintainAspectRatio)
           
static void writeImageToJPEG(java.awt.image.BufferedImage bufferedImage, java.io.File file)
           
static void writeImageToJPEG(java.awt.image.BufferedImage buffImage, int quality, java.io.File outputFile)
          This method is generally BETTER than ImageIO.write(...) as that produces low quality output.
static void writeImageToPNG(java.awt.image.RenderedImage rImage, java.io.File outputFile)
           
 
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

createWritableBuffer

public static java.awt.image.BufferedImage createWritableBuffer(int width,
                                                                int height)
Parameters:
width -
height -
Returns:

getTimeFromString

public static long getTimeFromString(java.lang.String timestampString)
Parses strings like 2005:03:30 19:20:23 and returns a java.sql.Timestamp object.

Parameters:
timestampString -
Returns:

isJPEGFile

public static boolean isJPEGFile(java.io.File imageFile)
Returns:
whether or not a file is a JPEG (just based on file extensions of .jpeg or .jpg) =]

readCaptureDateFromEXIF

public static java.lang.String readCaptureDateFromEXIF(java.io.File photoFile)
Gets the EXIF timestamp from a photo.

Parameters:
photoFile -
Returns:

readImage

public static java.awt.image.BufferedImage readImage(java.io.File source)
Parameters:
source -
Returns:

readSize

public static java.awt.Dimension readSize(java.io.File imageFile)
This works for both JPEG and non JPEG images/photos. It defaults to a generic method if it cannot find the jpeg EXIF.

Parameters:
imageFile -
Returns:

readSizeByLoading

public static java.awt.Dimension readSizeByLoading(java.io.File imageFile)
Load in the image file just to read the photo size... This should be slower than readSize(...) if most of your images are JPEG files with EXIF headers... Use it if you are loading non-JPEGS or if your JPEGs do not have EXIFs.

Parameters:
imageFile -
Returns:

readTimeFrom

public static long readTimeFrom(java.io.File photo)
If the EXIF field does not exist, it will return a time representing the file last modified date/time. TODO Would users rather pick the latest valid time read from the file system (based on an alphabetical sort by name), in the same directory? Maybe it should be a configurable option in whatever software uses this method?

Parameters:
photo -
Returns:

scaleImage

public static java.awt.image.BufferedImage scaleImage(java.awt.image.BufferedImage src,
                                                      float sX,
                                                      float sY)
Scaled a buffered image by the two scale parameters. The scale operation is anti-aliased.

Parameters:
src -
sX -
sY -
Returns:
A scaled BufferedImage

scaleImageToFit

public static java.awt.image.BufferedImage scaleImageToFit(java.awt.image.BufferedImage src,
                                                           int width,
                                                           int height)

scaleImageToSize

public static java.awt.image.BufferedImage scaleImageToSize(java.awt.image.BufferedImage src,
                                                            int targetWidth,
                                                            int targetHeight,
                                                            boolean maintainAspectRatio)

writeImageToJPEG

public static void writeImageToJPEG(java.awt.image.BufferedImage bufferedImage,
                                    java.io.File file)
Parameters:
bufferedImage -
file -

writeImageToJPEG

public static void writeImageToJPEG(java.awt.image.BufferedImage buffImage,
                                    int quality,
                                    java.io.File outputFile)
This method is generally BETTER than ImageIO.write(...) as that produces low quality output. This method will not work for a 4-banded image. The colors will look incorrect. Use the PNG version instead.

Parameters:
buffImage -
quality - goes from 0 to 100
outputFile -

writeImageToPNG

public static void writeImageToPNG(java.awt.image.RenderedImage rImage,
                                   java.io.File outputFile)
Parameters:
rImage -
outputFile -

Copyright 2006 Stanford University