public class IlvImageUtil extends Object
Modifier and Type | Method and Description |
---|---|
static BufferedImage |
createBufferedImage(Image image,
int imageType)
Creates a
BufferedImage of the specified type from the given
image. |
static Image |
getImageFromFile(Class<?> loader,
String file)
This is a utility method that creates an image from a file stored in a JAR
file.
|
static Dimension |
getImageSize(Image image)
Returns the size (dimensions) of an image.
|
static Image |
getScaledImage(Image orig,
int scaledWidth,
int scaledHeight,
boolean preserveAlpha,
int hints)
Creates a scaled image.
|
static Image |
loadImage(byte[] imagedata)
Loads an image from the specified byte array.
|
static Image |
loadImage(String fileName)
Loads an image from the specified file.
|
static BufferedImage |
loadImage(String fileName,
int imageType)
Loads an image from the specified file as a
BufferedImage of
the specified type. |
static Image |
loadImage(URL url)
Loads an image from the specified URL.
|
static BufferedImage |
loadImage(URL url,
int imageType)
Loads an image from the specified URL as a
BufferedImage of
the specified type. |
static Image |
loadImageFromFile(Class<?> loader,
String filename)
Utility method that loads an image from a file stored in a JAR file.
|
static void |
writeJPEGImage(BufferedImage image,
File filename)
Writes an image to the specified file, in JPEG format.
|
static void |
writeJPEGImage(BufferedImage image,
float quality,
File filename)
Writes an image to the specified file, in JPEG format, with given quality.
|
static void |
writeJPEGImage(BufferedImage image,
float quality,
OutputStream output)
Writes an image to the specified file, in JPEG format, with given quality.
|
static void |
writeJPEGImage(BufferedImage image,
OutputStream output)
Writes an image to the specified file, in JPEG format.
|
static void |
writePNGImage(BufferedImage image,
Color transparentColor,
File filename)
Writes an image to the specified file, in PNG format, with given
transparent color.
|
static void |
writePNGImage(BufferedImage image,
Color transparentColor,
OutputStream output)
Writes an image to the specified file, in PNG format, with given
transparent color.
|
static void |
writePNGImage(BufferedImage image,
File filename)
Writes an image to the specified file, in PNG format.
|
static void |
writePNGImage(BufferedImage image,
OutputStream output)
Writes an image to the specified file, in PNG format.
|
public static Image getImageFromFile(Class<?> loader, String file) throws IOException
InputStream
returned by the method getResourceAsStream
called on the
loader
object.loader
- The Class
object on which the method
getResourceAsStream
is called.file
- The location of the file that contains the image to be read. The
location must be specified according to the location of the
loader
class. For details, see the documentation of
Class.getResourceAsStream
.IOException
- An exception occurred while trying to read the bytes defining
the image.public static Image loadImageFromFile(Class<?> loader, String filename) throws IOException
loader
- The Class
object on which the method
getResourceAsStream
is called.filename
- The location of the file that contains the image to be read. The
location must be specified according to the location of the
loader
class.null
if the loading failed.IOException
- An exception occurred while trying to read the bytes defining
the image.getImageFromFile(java.lang.Class<?>, java.lang.String)
public static Image loadImage(URL url)
url
- The URL of the image.null
if the loading failed.public static Image loadImage(String fileName)
fileName
- The image file name.null
if the loading failed.public static Image loadImage(byte[] imagedata)
imagedata
- An array of bytes, representing the image.null
if the loading failed.public static Dimension getImageSize(Image image)
image
- The image.null
if the image is invalid.public static BufferedImage createBufferedImage(Image image, int imageType)
BufferedImage
of the specified type from the given
image.image
- The original image.imageType
- The type of the image to create. It can be any of the predefined
image types defined in the
java.awt.image.BufferedImage
class.public static BufferedImage loadImage(String fileName, int imageType)
BufferedImage
of
the specified type.
Note: This method can be about 10 times slower than
loadImage(String)
. Use it only if you need the result to be a
BufferedImage
.
fileName
- The image file name.imageType
- The type of the image to create. It can be any of the predefined
image types defined in the
java.awt.image.BufferedImage
class.null
if the loading failed.public static BufferedImage loadImage(URL url, int imageType)
BufferedImage
of
the specified type.
Note: This method can be about 10 times slower than loadImage(URL)
. Use it only if you need the result to be a BufferedImage
.
url
- The URL of the image.imageType
- The type of the image to create. It can be any of the predefined
image types defined in the
java.awt.image.BufferedImage
class.null
if the loading failed.public static void writeJPEGImage(BufferedImage image, File filename) throws IOException
image
- The contents of the image.filename
- Name of the file where it should be stored.IOException
public static void writeJPEGImage(BufferedImage image, OutputStream output) throws IOException
image
- The contents of the image.output
- The output destination.IOException
public static void writeJPEGImage(BufferedImage image, float quality, File filename) throws IOException
image
- The contents of the image.quality
- The quality, influences the JPEG compression factor. A value
between 0.0 and 1.0. 1.0 is the optimal quality, with no
compression.filename
- Name of the file where it should be stored.IOException
public static void writeJPEGImage(BufferedImage image, float quality, OutputStream output) throws IOException
image
- The contents of the image.quality
- The quality, influences the JPEG compression factor. A value
between 0.0 and 1.0. 1.0 is the optimal quality, with no
compression.output
- The output destination.IOException
public static void writePNGImage(BufferedImage image, File filename) throws IOException
image
- The contents of the image.filename
- Name of the file where it should be stored.IOException
public static void writePNGImage(BufferedImage image, OutputStream output) throws IOException
image
- The contents of the image.output
- The output destination.IOException
public static void writePNGImage(BufferedImage image, Color transparentColor, File filename) throws IOException
image
- The contents of the image.transparentColor
- The color to mark as transparent.filename
- Name of the file where it should be stored.IOException
public static void writePNGImage(BufferedImage image, Color transparentColor, OutputStream output) throws IOException
image
- The contents of the image.transparentColor
- The color to mark as transparent.output
- The output destination.IOException
public static Image getScaledImage(Image orig, int scaledWidth, int scaledHeight, boolean preserveAlpha, int hints)
orig
- The original image.scaledWidth
- The scaled widthscaledHeight
- The scaled heightpreserveAlpha
- Whether the alpha channel must be preserved.hints
- The flags to indicate the type of algorithm to use for image
resampling (Image.SCALE_FAST, ...).Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.