public class ImageUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REVISION |
Constructor and Description |
---|
ImageUtil() |
Modifier and Type | Method and Description |
---|---|
static java.io.File |
createGIFThumbnail(java.io.File imageFile,
int maxWidth,
int maxHeight)
Creates a thumbnail of the given file image in a temporary location
in the GIF format, return the corresponding File.
|
static java.io.File |
createJPEGThumbnail(java.io.File imageFile,
int maxWidth,
int maxHeight)
Creates a thumbnail of the given file image in a temporary location
in the JPEG format, return the corresponding File.
|
static java.io.File |
createThumbnail(java.io.File imageFile,
ImageFormat format,
int maxWidth,
int maxHeight) |
static java.io.File |
createThumbnail(java.io.File imageFile,
ImageFormat format,
int maxWidth,
int maxHeight,
java.lang.String background)
Creates a thumbnail of the given file image in a temporary location
in the given format, return the corresponding File.
|
static java.io.File |
crop(java.io.File imageFile,
ImageFormat format,
int x1,
int y1,
int x2,
int y2,
java.lang.String background) |
static java.awt.image.BufferedImage |
cropImage(java.awt.image.BufferedImage image,
int x1,
int y1,
int x2,
int y2,
java.lang.String background) |
static java.awt.image.BufferedImage |
getScaledInstance(java.awt.image.BufferedImage img,
int targetWidth,
int targetHeight,
java.lang.Object hint,
boolean higherQuality)
Convenience method that returns a scaled instance of the
provided
BufferedImage . |
static java.lang.String[] |
getSupportedReadFormat() |
static java.lang.String[] |
getSupportedWriteFormat() |
static boolean |
isImage(java.io.File file)
Detects if the given file is an image file, using its extension.
|
static java.awt.image.BufferedImage |
readImage(java.io.File file)
Read the given image file and return the BufferedImage
|
static java.awt.image.BufferedImage |
resizeImage(java.awt.image.BufferedImage image,
int maxWidth,
int maxHeight,
boolean doNotEnlarge,
java.lang.String background)
Resizes the given BufferedImage to a new BufferedImage file with the given
sizes.
|
static java.io.File |
rotate(java.io.File imageFile,
ImageFormat format,
int angle,
java.lang.String background) |
static java.awt.image.BufferedImage |
rotateImage(java.awt.image.BufferedImage image,
int angle,
java.lang.String background) |
static void |
setQualityRenderingHints(java.awt.Graphics2D g2d) |
static java.io.File |
writeGIF(java.awt.image.BufferedImage image,
java.io.File outFile)
Write the given BufferedImage to the given outfile in GIF format.
|
static java.io.File |
writeJPEG(java.awt.image.BufferedImage image,
java.io.File outFile)
Write the given BufferedImage to the given outfile in JPEG format.
|
public static final java.lang.String REVISION
public static boolean isImage(java.io.File file)
file
- the file to checkpublic static java.io.File createGIFThumbnail(java.io.File imageFile, int maxWidth, int maxHeight)
imageFile
- the image file of which to make a thumbnail.maxWidth
- the maximum width of the output imagemaxHeight
- the maximum height of the output imagecreateThumbnail(File, ImageFormat, int, int)
public static java.io.File createJPEGThumbnail(java.io.File imageFile, int maxWidth, int maxHeight)
imageFile
- the image file of which to make a thumbnail.maxWidth
- the maximum width of the output imagemaxHeight
- the maximum height of the output imagecreateThumbnail(File, ImageFormat, int, int)
public static java.io.File createThumbnail(java.io.File imageFile, ImageFormat format, int maxWidth, int maxHeight)
public static java.io.File createThumbnail(java.io.File imageFile, ImageFormat format, int maxWidth, int maxHeight, java.lang.String background)
imageFile
- the image file of which to make a thumbnail.format
- the image format to use, ImageFormat.GIF
, ImageFormat.JPEG
,
if null the ImageFormat.JPEG
format is usedmaxWidth
- the maximum width of the output imagemaxHeight
- the maximum height of the output imagebackground
- the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeightpublic static java.awt.image.BufferedImage readImage(java.io.File file)
file
- the image file to readjava.lang.IllegalArgumentException
- if file is null.public static void setQualityRenderingHints(java.awt.Graphics2D g2d)
public static java.awt.image.BufferedImage getScaledInstance(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint, boolean higherQuality)
BufferedImage
.
http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.htmlimg
- the original image to be scaledtargetWidth
- the desired width of the scaled instance,
in pixelstargetHeight
- the desired height of the scaled instance,
in pixelshint
- one of the rendering hints that corresponds to
RenderingHints.KEY_INTERPOLATION
(e.g.
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
,
RenderingHints.VALUE_INTERPOLATION_BILINEAR
,
RenderingHints.VALUE_INTERPOLATION_BICUBIC
)higherQuality
- if true, this method will use a multi-step
scaling technique that provides higher quality than the usual
one-step technique (only useful in downscaling cases, where
targetWidth
or targetHeight
is
smaller than the original dimensions, and generally only when
the BILINEAR
hint is specified)BufferedImage
public static java.io.File rotate(java.io.File imageFile, ImageFormat format, int angle, java.lang.String background)
public static java.awt.image.BufferedImage rotateImage(java.awt.image.BufferedImage image, int angle, java.lang.String background)
public static java.io.File crop(java.io.File imageFile, ImageFormat format, int x1, int y1, int x2, int y2, java.lang.String background)
public static java.awt.image.BufferedImage cropImage(java.awt.image.BufferedImage image, int x1, int y1, int x2, int y2, java.lang.String background)
public static java.awt.image.BufferedImage resizeImage(java.awt.image.BufferedImage image, int maxWidth, int maxHeight, boolean doNotEnlarge, java.lang.String background)
image
- the image to resize.maxWidth
- the maximum width of the output imagemaxHeight
- the maximum height of the output imagedoNotEnlarge
- do not increase image size if image is smaller than given maximum dimension.background
- the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeightjava.lang.IllegalArgumentException
- if image is null.public static java.io.File writeJPEG(java.awt.image.BufferedImage image, java.io.File outFile)
image
- the BufferedImage to write to a file.outFile
- the file in which to write the imagejava.lang.IllegalArgumentException
- if image or outFile is null.public static java.io.File writeGIF(java.awt.image.BufferedImage image, java.io.File outFile)
image
- the BufferedImage to write to a file.outFile
- the file in which to write the imagejava.lang.IllegalArgumentException
- if image or outFile is null.public static java.lang.String[] getSupportedReadFormat()
ImageIO.getReaderFormatNames()
public static java.lang.String[] getSupportedWriteFormat()
ImageIO.getWriterFormatNames()
Copyright © 2001-2010 Jalios SA. All Rights Reserved.