|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bristle.javalib.awt.ImgUtil
public class ImgUtil
This class contains utility routines for manipulating images.
Usage:
- The typical scenario for using this class is:
- To convert an Image to a BufferedImage:
BufferedImage bi = ImgUtil.toBufferedImage(image);
Assumptions:
Effects:
- None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
$Log$
| Nested Class Summary | |
|---|---|
static class |
ImgUtil.NoImageFoundException
This exception is thrown when the specified data source (InputStream, file, etc) contains no image. |
static class |
ImgUtil.ScaleAlgorithm
This class represents an enumerated type that specifies whether scaling of Images should be done with an emphasis on speed or image smoothness. |
static class |
ImgUtil.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
| Field Summary | |
|---|---|
static boolean |
blnPRESERVE_ASPECT_RATIO
|
static int |
intMAX_SCALE_CURRENT_SIZE
|
static int |
intMAX_SCALE_DOUBLE_CURRENT_SIZE
|
static int |
intMAX_SCALE_NO_LIMIT
|
static int |
intMAX_SCALE_TRIPLE_CURRENT_SIZE
|
| Constructor Summary | |
|---|---|
ImgUtil()
|
|
| Method Summary | |
|---|---|
static boolean |
getAwtHeadless()
Return true if AWT is set to run in headless mode. |
static Image |
getScaledImage(Image img,
int intWidth,
int intHeight,
ImgUtil.ScaleAlgorithm algorithm)
Returns a scaled copy of the specified Image. |
static Image |
readImageFromFile(String strFilename)
Read an Image from the specified filename. |
static Image |
readImageFromInputStream(InputStream in)
Read an Image from the specified InputStream. |
static void |
scaleImageToFileAsJPEG(String strFilenameIn,
String strFilenameOut,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified filename to the specified filename, converting it to a JPEG, and scaling it by the specified percent. |
static void |
scaleImageToFileAsJPEG(String strFilenameIn,
String strFilenameOut,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified filename to the specified filename, converting it to a JPEG, and scaling it to the specified size. |
static void |
scaleImageToOutputStreamAsJPEG(Image img,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Write the specified Image to the specified OutputStream, converting it to a JPEG, and scaling it by the specified percent. |
static void |
scaleImageToOutputStreamAsJPEG(Image img,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Write the specified Image to the specified OutputStream, converting it to a JPEG, and scaling it to the specified size. |
static void |
scaleImageToOutputStreamAsJPEG(InputStream in,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified InputStream to the specified OutputStream, converting it to a JPEG, and scaling it by the specified percent. |
static void |
scaleImageToOutputStreamAsJPEG(InputStream in,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified InputStream to the specified OutputStream, converting it to a JPEG, and scaling it to the specified size. |
static void |
scaleImageToOutputStreamAsJPEG(String strFilename,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified filename to the specified OutputStream, converting it to a JPEG, and scaling it by the specified percent. |
static void |
scaleImageToOutputStreamAsJPEG(String strFilename,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
Copy an image from the specified filename to the specified OutputStream, converting it to a JPEG, and scaling it to the specified size. |
static void |
setAwtHeadless()
Set AWT to run in headless mode, meaning there is no local graphical display on the server. |
static BufferedImage |
toBufferedImage(Image img)
Returns a BufferedImage from the specified Image. |
static void |
writeImageToFileAsJPEG(Image img,
String strFilename)
Write the specified Image to the file with the specified name, converting it to a JPEG. |
static void |
writeImageToOutputStreamAsJPEG(Image img,
OutputStream out)
Write the specified Image to the specified OutputStream, converting it to a JPEG. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final boolean blnPRESERVE_ASPECT_RATIO
public static final int intMAX_SCALE_CURRENT_SIZE
public static final int intMAX_SCALE_DOUBLE_CURRENT_SIZE
public static final int intMAX_SCALE_TRIPLE_CURRENT_SIZE
public static final int intMAX_SCALE_NO_LIMIT
| Constructor Detail |
|---|
public ImgUtil()
| Method Detail |
|---|
public static void setAwtHeadless()
public static boolean getAwtHeadless()
setAwtHeadless()public static BufferedImage toBufferedImage(Image img)
img - The input Image
public static Image getScaledImage(Image img,
int intWidth,
int intHeight,
ImgUtil.ScaleAlgorithm algorithm)
img - The input ImageintWidth - The desired Image width, or negative number to
maintain the original aspect ratio.intHeight - The desired Image height, or negative number to
maintain the original aspect ratio.algorithm - Algorithm to use for scaling.
public static Image readImageFromInputStream(InputStream in)
throws IOException,
ImgUtil.NoImageFoundException
in - The InputStream to read the Image from.
IOException - When an error occurs reading the Image.
ImgUtil.NoImageFoundException - When the InputStream contains no Image.
public static Image readImageFromFile(String strFilename)
throws IOException,
ImgUtil.NoImageFoundException
strFilename - The name of the file to read the Image from.
IOException - When an error occurs reading the Image.
ImgUtil.NoImageFoundException - When the file contains no Image.
public static void writeImageToOutputStreamAsJPEG(Image img,
OutputStream out)
throws IOException
img - The input Imageout - The OutputStream
IOException - When an error occurs writing the Image.
public static void scaleImageToOutputStreamAsJPEG(Image img,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException
img - The input Imageout - The OutputStreamintWidth - The desired Image width, or negative number to
maintain the original aspect ratio.intHeight - The desired Image height, or negative number to
maintain the original aspect ratio.blnPreserveAspectRatio - If true, preserve the aspect ratio of the Image
even if neither intWidth nor intHeight is negative.
Scale to the largest size that will fit within both
specified dimensions.intMaxScalePercent - Max percent to scale the image, or negative number
for no limit. This is useful to avoid scaling images
too much and having them become grainy when scaling
to a fixed size. It may be better to be less than the
intended size than to be too grainy. Common values
are:
intMAX_SCALE_CURRENT_SIZE (100%)
intMAX_SCALE_DOUBLE_CURRENT_SIZE (200%)
intMAX_SCALE_TRIPLE_CURRENT_SIZE (300%)
intMAX_SCALE_NO_LIMIT (-1)algorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the Image.
public static void scaleImageToOutputStreamAsJPEG(InputStream in,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
in - The InputStreamout - The OutputStreamintWidth - The desired Image width, or negative number to
maintain the original aspect ratio.intHeight - The desired Image height, or negative number to
maintain the original aspect ratio.blnPreserveAspectRatio - If true, preserve the aspect ratio of the Image
even if neither intWidth nor intHeight is negative.
Scale to the largest size that will fit within both
specified dimensions.intMaxScalePercent - Max percent to scale the image, or negative number
for no limit.
See scaleImageToOutputStreamAsJPEG(Image,
OutputStream, int, int, boolean, int, ScaleAlgorithm)algorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the image.
ImgUtil.NoImageFoundException - When the InputStream contains no Image.
public static void scaleImageToOutputStreamAsJPEG(String strFilename,
OutputStream out,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
strFilename - The input filenameout - The OutputStreamintWidth - The desired Image width, or negative number to
maintain the original aspect ratio.intHeight - The desired Image height, or negative number to
maintain the original aspect ratio.blnPreserveAspectRatio - If true, preserve the aspect ratio of the Image
even if neither intWidth nor intHeight is negative.
Scale to the largest size that will fit within both
specified dimensions.intMaxScalePercent - Max percent to scale the image, or negative number
for no limit.
See scaleImageToOutputStreamAsJPEG(Image,
OutputStream, int, int, boolean, int, ScaleAlgorithm)algorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the image.
ImgUtil.NoImageFoundException - When the file contains no Image.
public static void scaleImageToOutputStreamAsJPEG(Image img,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException
img - The input Imageout - The OutputStreamintScalePercent - The desired scale percentalgorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the Image.
public static void scaleImageToOutputStreamAsJPEG(InputStream in,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
in - The InputStreamout - The OutputStreamintScalePercent - The desired scale percentalgorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the Image.
ImgUtil.NoImageFoundException - When the InputStream contains no Image.
public static void scaleImageToOutputStreamAsJPEG(String strFilename,
OutputStream out,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
strFilename - The input filenameout - The OutputStreamintScalePercent - The desired scale percentalgorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the Image.
ImgUtil.NoImageFoundException - When the file contains no Image.
public static void writeImageToFileAsJPEG(Image img,
String strFilename)
throws IOException
img - The input ImagestrFilename - The name of the file to write to.
IOException - When an error occurs writing the Image.
public static void scaleImageToFileAsJPEG(String strFilenameIn,
String strFilenameOut,
int intWidth,
int intHeight,
boolean blnPreserveAspectRatio,
int intMaxScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
strFilenameIn - The input filenamestrFilenameOut - The name of the file to write to.intWidth - The desired Image width, or negative number to
maintain the original aspect ratio.intHeight - The desired Image height, or negative number to
maintain the original aspect ratio.blnPreserveAspectRatio - If true, preserve the aspect ratio of the Image
even if neither intWidth nor intHeight is negative.
Scale to the largest size that will fit within both
specified dimensions.intMaxScalePercent - Max percent to scale the image, or negative number
for no limit.
See scaleImageToOutputStreamAsJPEG(Image,
OutputStream, int, int, boolean, int, ScaleAlgorithm)algorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the image.
ImgUtil.NoImageFoundException - When the file contains no Image.
public static void scaleImageToFileAsJPEG(String strFilenameIn,
String strFilenameOut,
int intScalePercent,
ImgUtil.ScaleAlgorithm algorithm)
throws IOException,
ImgUtil.NoImageFoundException
strFilenameIn - The input filenamestrFilenameOut - The name of the file to write to.intScalePercent - The desired scale percentalgorithm - Algorithm to use for scaling.
IOException - When an error occurs reading or writing the image.
ImgUtil.NoImageFoundException - When the file contains no Image.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||