public class ImageUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ImageUtils.ScalingStrategy
The available strategies for scaling images.
|
Modifier | Constructor and Description |
---|---|
protected |
ImageUtils()
Prevent instantiation
|
Modifier and Type | Method and Description |
---|---|
static InputStream |
convertToRGB(InputStream is,
ColorModel colorModel)
Converts image raster data to a JPEG with RGB color space.
|
static InputStream |
convertToRGB(InputStream is,
ImageMetaData.ColorModel colorModel)
Deprecated.
This method is deprecated in favor of
convertToRGB(InputStream is, ColorModel colorModel) |
static String |
fixMimeType(String mimeType)
Deprecated.
Use MimeTypeHelper.sanitizeMimeType instead
|
static ImageReader |
getImageReader(String aMimeType)
Returns an image reader for a MIME type.
|
static ImageWriter |
getImageWriter(String aMimeType)
Returns an image writer for a MIME type.
|
static BufferedImage |
scaleImage(BufferedImage img,
int targetWidth,
int targetHeight,
ImageUtils.ScalingStrategy strategy)
Returns a scaled instance of the provided
BufferedImage . |
static BufferedImage |
scaleImage(BufferedImage img,
int xOffset,
int yOffset,
int sourceWidth,
int sourceHeight,
int targetWidth,
int targetHeight,
Object hint,
boolean highQuality) |
static BufferedImage |
scaleImage(BufferedImage img,
int targetWidth,
int targetHeight,
Object hint,
boolean highQuality)
Deprecated.
Use
scaleImage(java.awt.image.BufferedImage, int, int, org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils.ScalingStrategy) instead
for faster scaling and/or better image quality)} |
static ByteArrayOutputStream |
writeImage(ImageWriter writer,
BufferedImage image)
Returns the data of a
BufferedImage as a binary output stream. |
static ByteArrayOutputStream |
writeImage(ImageWriter writer,
BufferedImage image,
float compressionQuality)
Returns the data of a
BufferedImage as a binary output stream. |
@Deprecated public static String fixMimeType(String mimeType)
mimeType
- the MIME type to fixpublic static ImageReader getImageReader(String aMimeType)
aMimeType
- MIME typenull
if no image reader could be created
for the given MIME type.public static ImageWriter getImageWriter(String aMimeType)
aMimeType
- MIME typenull
if no image writer could be created
for the given MIME type.public static ByteArrayOutputStream writeImage(ImageWriter writer, BufferedImage image, float compressionQuality) throws IOException
BufferedImage
as a binary output stream. If the image is null
,
a stream of zero bytes is returned.writer
- the writer to use for writing the image data.image
- the image to write.compressionQuality
- a float between 0 and 1 that indicates the desired compression quality. Values lower than
0 will be interpreted as 0, values higher than 1 will be interpreted as 1.IOException
- when creating the binary output stream failed.public static ByteArrayOutputStream writeImage(ImageWriter writer, BufferedImage image) throws IOException
BufferedImage
as a binary output stream. If the image is null
, a
stream of zero bytes is returned. The data is written with a compression quality of 1.writer
- the writer to use for writing the image data.image
- the image to write.IOException
- when creating the binary output stream failed.public static BufferedImage scaleImage(BufferedImage img, int targetWidth, int targetHeight, ImageUtils.ScalingStrategy strategy)
BufferedImage
.img
- the original image to be scaledtargetWidth
- the desired width of the scaled instance, in pixelstargetHeight
- the desired height of the scaled instance, in pixelsstrategy
- the strategy to use for scaling the imageBufferedImage
, or null
if either
the target width or target height is 0 or less.@Deprecated public static BufferedImage scaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean highQuality)
scaleImage(java.awt.image.BufferedImage, int, int, org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils.ScalingStrategy)
instead
for faster scaling and/or better image quality)}BufferedImage
.img
- 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
)highQuality
- 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
, or null
if either
the target width or target height is 0 or less.public static BufferedImage scaleImage(BufferedImage img, int xOffset, int yOffset, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, Object hint, boolean highQuality)
public static InputStream convertToRGB(InputStream is, ColorModel colorModel) throws IOException, UnsupportedImageException
is
- the image datacolorModel
- the color model of the imageIOException
UnsupportedImageException
@Deprecated public static InputStream convertToRGB(InputStream is, ImageMetaData.ColorModel colorModel) throws IOException, UnsupportedImageException
convertToRGB(InputStream is, ColorModel colorModel)
convertToRGB(InputStream is, ColorModel colorModel)
is
- the image datacolorModel
- the color model of the imageIOException
UnsupportedImageException
Copyright © 2007–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.