|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.programix.gui.image.ImageTools
public class ImageTools
Collection of functions useful for working with Image and
BufferedImage.
| Nested Class Summary | |
|---|---|
static class |
ImageTools.ImageException
Thrown to indicate that there was a problem reading, writing, converting, or other problems working with an Image or
BufferedImage. |
static class |
ImageTools.ImageNotFoundException
|
| Field Summary | |
|---|---|
static String |
JPEG_FORMAT
|
static String |
PNG_FORMAT
|
| Method Summary | |
|---|---|
static void |
closeQuietly(ImageInputStream iis)
|
static void |
closeQuietly(ImageOutputStream ios)
|
static BufferedImage |
convertToBuffered(Image image)
Converts the passed Image into a BufferedImage
if necessary. |
static byte[] |
createBytes(RenderedImage image,
String format)
|
static BufferedImage |
createImage(byte[] formattedImageBytes)
Creates a BufferedImage by reading from the specified
byte[]. |
static BufferedImage |
createImage(File source)
Creates a BufferedImage by reading from the specified file. |
static BufferedImage |
createImage(InputStream source)
Creates a BufferedImage by reading from the specified source
which should be presenting the data in a PNG, JPEG, GIF, etc. |
static BufferedImage |
createImage(URL imageUrl)
Creates a BufferedImage by reading from the specified
URL. |
static BufferedImage |
createImageFromFile(String filename)
Creates a BufferedImage by reading from the specified file. |
static BufferedImage |
createImageFromResource(String resourceLocation)
Creates a BufferedImage by reading from the specified resource. |
static BufferedImage |
createImageFromResource(String resourceLocation,
Class<?> searchStartPoint)
Creates a BufferedImage by reading from the specified resource. |
static byte[] |
createJPEGBytes(RenderedImage image)
|
static byte[] |
createPNGBytes(RenderedImage image)
|
static void |
write(RenderedImage image,
OutputStream destination,
String format)
Writes out the specified image to the specified stream in the specified format. |
static void |
writeJPEG(RenderedImage image,
OutputStream destination)
|
static void |
writePNG(RenderedImage image,
OutputStream destination)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String PNG_FORMAT
public static final String JPEG_FORMAT
| Method Detail |
|---|
public static BufferedImage createImage(InputStream source)
throws ImageTools.ImageException
BufferedImage by reading from the specified source
which should be presenting the data in a PNG, JPEG, GIF, etc. format.
The InputStream passed in is closed by this method.
source - origin of the image; stream is always closed by this method
ImageTools.ImageException - if there is no support for the image format
or if there is any problem reading from the stream.
public static BufferedImage createImage(File source)
throws ImageTools.ImageNotFoundException,
ImageTools.ImageException
BufferedImage by reading from the specified file.
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
source - origin of the image
ImageTools.ImageNotFoundException - if the specified file can not be found.
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static BufferedImage createImageFromFile(String filename)
throws ImageTools.ImageNotFoundException,
ImageTools.ImageException
BufferedImage by reading from the specified file.
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
filename - origin of the image
ImageTools.ImageNotFoundException - if the specified file can not be found.
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static BufferedImage createImage(URL imageUrl)
throws ImageTools.ImageException
BufferedImage by reading from the specified
URL.
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
imageUrl - origin of the image
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static BufferedImage createImageFromResource(String resourceLocation,
Class<?> searchStartPoint)
throws ImageTools.ImageNotFoundException,
ImageTools.ImageException
BufferedImage by reading from the specified resource.
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
The underlying InputStream comes from the specified
resourceLocation.
This method is suitable for retrieving resources from JAR files,
WAR files, and CLASSPATH's.
The getResource(String path)
method on the Class object passed in is used
to locate the requested resource.
See IOTools.getUrlForResource(String, Class) for the full explanation
of how the search for the URL is performed.
Works like this (with IOExceptions converted to ImageExceptions):
returncreateImage(IOTools.getInputStreamForResource( resourceLocation, searchStartPoint));
resourceLocation - the path to the resourcesearchStartPoint - the Class to invoke
getResource on.
If null, IOTools.class is used.
ImageTools.ImageNotFoundException - if the specified resource can
not be found.
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static BufferedImage createImageFromResource(String resourceLocation)
throws ImageTools.ImageNotFoundException,
ImageTools.ImageException
BufferedImage by reading from the specified resource.
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
The underlying InputStream comes from the specified
resourceLocation.
This method is suitable for retrieving resources from JAR files,
WAR files, and CLASSPATH's.
See IOTools.getUrlForResource(String, Class) for the full explanation
of how the search for the URL is performed.
Works like this (with IOExceptions converted to ImageExceptions):
returncreateImage(IOTools.getInputStreamForResource(resourceLocation));
resourceLocation - the path to the resource
ImageTools.ImageNotFoundException - if the specified resource can
not be found.
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static BufferedImage createImage(byte[] formattedImageBytes)
throws ImageTools.ImageException
BufferedImage by reading from the specified
byte[].
The image's data must be in a PNG, JPEG, GIF, or other format that can
be read by ImageIO.
formattedImageBytes - origin of the image
ImageTools.ImageException - if there is no support for the image format
or if there is any other problem reading from the stream.
public static void write(RenderedImage image,
OutputStream destination,
String format)
throws ImageTools.ImageException
OutputStream pass to this method
is not closed.
image - image to convert to bytesdestination - stream for formatted bytes to be sent; this is
flushed, but not closed by this method.format - image format for output, like
PNG_FORMAT or JPEG_FORMAT or another other
format supported for writing.
ImageTools.ImageException - if there are any problems writing out
the formatted bytes.
public static void writePNG(RenderedImage image,
OutputStream destination)
throws ImageTools.ImageException
ImageTools.ImageException
public static void writeJPEG(RenderedImage image,
OutputStream destination)
throws ImageTools.ImageException
ImageTools.ImageException
public static byte[] createBytes(RenderedImage image,
String format)
throws ImageTools.ImageException
ImageTools.ImageException
public static byte[] createPNGBytes(RenderedImage image)
throws ImageTools.ImageException
ImageTools.ImageException
public static byte[] createJPEGBytes(RenderedImage image)
throws ImageTools.ImageException
ImageTools.ImageException
public static BufferedImage convertToBuffered(Image image)
throws IllegalArgumentException
Image into a BufferedImage
if necessary. That is, is a BufferedImage is passed in,
then that same object is simple returned. If null is
passed in, then an IllegalArgumentException is thrown.
If the passed image is not a BufferedImage, a new
BufferedImage is created and the original image is drawn
onto it.
IllegalArgumentExceptionpublic static void closeQuietly(ImageInputStream iis)
public static void closeQuietly(ImageOutputStream ios)
|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||