public class ImageUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static float |
DEFAULT_IMAGE_OPTIMAL_RESCALING_FACTOR
When a grayscale image with color depth > 8 bits has to be displayed and user has not decided
how it should be converted, then this threshold will be used.
|
static java.lang.String |
GIF_FILE |
static java.lang.String |
JPEG_FILE |
static java.lang.String |
PNG_FILE |
static java.lang.String |
TIFF_FILE |
Constructor and Description |
---|
ImageUtil() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
convertForDisplayIfNecessary(java.awt.image.BufferedImage image)
If the specified image uses grayscale with color depth larger then 8 bits, conversion to 8
bits grayscale is done.
|
static java.awt.image.BufferedImage |
convertForDisplayIfNecessary(java.awt.image.BufferedImage image,
float threshold)
If the specified image uses grayscale with color depth larger then 8 bits, conversion to 8
bits grayscale is done.
|
static java.awt.image.BufferedImage |
createThumbnailForDisplay(java.awt.image.BufferedImage image,
int maxWidth,
int maxHeight)
Re-scales the image to be the biggest one which fits into a (0,0,maxWidth, maxHeight)
rectangle.
|
static byte[] |
imageToPng(java.awt.image.BufferedImage image)
Converts the given image to a PNG image.
|
static byte[] |
imageToPng(java.awt.image.BufferedImage image,
ar.com.hjg.pngj.PngFilterType filterType,
int compressionLevel)
Converts the given image to a PNG image.
|
static byte[] |
imageToPngFast(java.awt.image.BufferedImage image)
Converts the given image to a PNG image.
|
static boolean |
isGif(java.lang.String fileTypeOrNull)
Returns
true if the fileTypeOrNull is a gif file. |
static boolean |
isImageFile(java.io.File file)
Returns
true if the specified file is a supported image file. |
static boolean |
isJpeg(java.lang.String fileTypeOrNull)
Returns
true if the fileTypeOrNull is a jpeg file. |
static boolean |
isPng(java.lang.String fileTypeOrNull)
Returns
true if the fileTypeOrNull is a png file. |
static boolean |
isTiff(java.lang.String fileTypeOrNull)
Returns
true if the fileTypeOrNull is a tiff file. |
static int |
loadColorDepthJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle,
ch.systemsx.cisd.imagereaders.ImageID imageID)
For experts only! Loads some kinds of TIFF images handled by JAI library.
|
static java.awt.Dimension |
loadDimensionJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle,
ch.systemsx.cisd.imagereaders.ImageID imageID)
For experts only! Loads some kinds of TIFF images handled by JAI library.
|
static java.awt.image.BufferedImage |
loadImageForDisplay(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode)
Loads an image from specified file node.
|
static java.awt.image.BufferedImage |
loadJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle,
ch.systemsx.cisd.imagereaders.ImageID imageID)
For experts only! Loads some kinds of TIFF images handled by JAI library.
|
static java.awt.image.BufferedImage |
loadUnchangedImage(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode,
java.lang.String imageIdOrNull,
java.lang.String imageLibraryNameOrNull,
java.lang.String imageLibraryReaderNameOrNull,
ch.systemsx.cisd.imagereaders.IReadParams params)
Loads the image specified by imageIdOrNull from the given inputStream.
|
static int |
loadUnchangedImageColorDepth(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode,
java.lang.String imageIdOrNull,
java.lang.String imageLibraryNameOrNull,
java.lang.String imageLibraryReaderNameOrNull)
Loads the color depth of image specified by imageIdOrNull from the given
inputStream.
|
static java.awt.Dimension |
loadUnchangedImageDimension(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode,
java.lang.String imageIdOrNull,
java.lang.String imageLibraryNameOrNull,
java.lang.String imageLibraryReaderNameOrNull)
Loads the size of image specified by imageIdOrNull from the given
inputStream.
|
static ch.systemsx.cisd.imagereaders.ImageID |
parseImageID(java.lang.String imageIdOrNull,
ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode)
Parses specified string representation of an
ImageID . |
static java.awt.image.BufferedImage |
rescale(java.awt.image.BufferedImage image,
int maxWidth,
int maxHeight,
boolean enlargeIfNecessary,
boolean highQuality8Bit)
Re-scales the image to be the biggest one which fits into a (0,0,maxWidth, maxHeight)
rectangle.
|
static java.lang.String |
tryToFigureOutFileTypeOf(ch.systemsx.cisd.base.io.IRandomAccessFile handle)
Tries to figure out the file type of the specified binary content.
|
static void |
writeImageToPng(java.awt.image.BufferedImage image,
java.io.OutputStream out)
Converts the given image to a PNG image and writes it to the given output stream.
|
static void |
writeImageToPng(java.awt.image.BufferedImage image,
java.io.OutputStream out,
ar.com.hjg.pngj.PngFilterType filterType,
int compressionLevel)
Converts the given image to a PNG image and writes it to the given output stream.
|
static void |
writeImageToPngFast(java.awt.image.BufferedImage image,
java.io.OutputStream out)
Converts the given image to a PNG image and writes it to the given output stream.
|
static void |
writeImageUsingImageIO(java.awt.image.BufferedImage image,
java.io.OutputStream out,
java.lang.String format) |
public static final java.lang.String TIFF_FILE
public static final java.lang.String PNG_FILE
public static final java.lang.String JPEG_FILE
public static final java.lang.String GIF_FILE
public static final float DEFAULT_IMAGE_OPTIMAL_RESCALING_FACTOR
public static java.awt.image.BufferedImage loadJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle, ch.systemsx.cisd.imagereaders.ImageID imageID) throws EnvironmentFailureException
EnvironmentFailureException
public static java.awt.Dimension loadDimensionJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle, ch.systemsx.cisd.imagereaders.ImageID imageID) throws EnvironmentFailureException
EnvironmentFailureException
public static int loadColorDepthJavaAdvancedImagingTiff(ch.systemsx.cisd.base.io.IRandomAccessFile handle, ch.systemsx.cisd.imagereaders.ImageID imageID) throws EnvironmentFailureException
EnvironmentFailureException
public static boolean isImageFile(java.io.File file)
true
if the specified file is a supported image file. Supported formats
are GIF, JPG, PNG, TIFF. Only file type is taken into account for figuring out the image
format. Following file types are recognized:
.gif, .jpg, .jpeg, .png, .tif, .tiff
public static java.awt.image.BufferedImage loadUnchangedImage(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode, java.lang.String imageIdOrNull, java.lang.String imageLibraryNameOrNull, java.lang.String imageLibraryReaderNameOrNull, ch.systemsx.cisd.imagereaders.IReadParams params)
Note that the original color depth will be kept, so e.g. 12 or 16 bit grayscale images will not be converted to RGB.
java.lang.IllegalArgumentException
- if the input stream doesn't start with a magic number
identifying supported image format.public static java.awt.Dimension loadUnchangedImageDimension(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode, java.lang.String imageIdOrNull, java.lang.String imageLibraryNameOrNull, java.lang.String imageLibraryReaderNameOrNull)
java.lang.IllegalArgumentException
- if the input stream doesn't start with a magic number
identifying supported image format.public static int loadUnchangedImageColorDepth(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode, java.lang.String imageIdOrNull, java.lang.String imageLibraryNameOrNull, java.lang.String imageLibraryReaderNameOrNull)
java.lang.IllegalArgumentException
- if the input stream doesn't start with a magic number
identifying supported image format.public static byte[] imageToPngFast(java.awt.image.BufferedImage image)
This method is about 7 times faster than
ImageIO.write(java.awt.image.RenderedImage, String, java.io.OutputStream)
and should
be preferred whenever speed is important.
image
- The image to convert to the PNG byte[]
.public static void writeImageToPngFast(java.awt.image.BufferedImage image, java.io.OutputStream out)
This method is about 7 times faster than
ImageIO.write(java.awt.image.RenderedImage, String, java.io.OutputStream)
and should
be preferred whenever speed is important.
image
- The image to write to the output stream.out
- The output stream to write the png converted image to.public static byte[] imageToPng(java.awt.image.BufferedImage image)
This method is about 7 times faster than
ImageIO.write(java.awt.image.RenderedImage, String, java.io.OutputStream)
and should
be preferred whenever speed is important.
image
- The image to convert to the PNG byte[]
.public static void writeImageToPng(java.awt.image.BufferedImage image, java.io.OutputStream out)
This method is about 3 times faster than
ImageIO.write(java.awt.image.RenderedImage, String, java.io.OutputStream)
and should
be preferred whenever speed is important.
image
- The image to write to the output stream.out
- The output stream to write the png converted image to.public static byte[] imageToPng(java.awt.image.BufferedImage image, ar.com.hjg.pngj.PngFilterType filterType, int compressionLevel)
image
- The image to write to the output stream.filterType
- The type of the filter (see PNG filters) to apply when
converting to PNG, null
means PngFilterType.FILTER_DEFAULT
.compressionLevel
- the compression level for the deflation filter of the PNG conversion,
from -1 to 9. 0 means no compression, 9 means maximal compression, -1 means 6
which is the default deflation level.public static void writeImageToPng(java.awt.image.BufferedImage image, java.io.OutputStream out, ar.com.hjg.pngj.PngFilterType filterType, int compressionLevel)
image
- The image to write to the output stream.out
- The output stream to write the png converted image tofilterType
- The type of the filter (see PNG filters) to apply when
converting to PNG, null
means PngFilterType.FILTER_DEFAULT
.compressionLevel
- the compression level for the deflation filter of the PNG conversion,
from -1 to 9. 0 means no compression, 9 means maximal compression, -1 means 6
which is the default deflation level.public static void writeImageUsingImageIO(java.awt.image.BufferedImage image, java.io.OutputStream out, java.lang.String format) throws ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked
ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked
public static ch.systemsx.cisd.imagereaders.ImageID parseImageID(java.lang.String imageIdOrNull, ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode)
ImageID
. If the argument is
null
ImageID.NULL
will be returned.public static java.awt.image.BufferedImage loadImageForDisplay(ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode contentNode)
java.lang.IllegalArgumentException
- if the file isn't a valid image file.public static java.awt.image.BufferedImage createThumbnailForDisplay(java.awt.image.BufferedImage image, int maxWidth, int maxHeight)
If the specified image uses grayscale with color depth larger then 8 bits, conversion to 8 bits grayscale is done.
maxWidth
- Maximum width of the result image.maxHeight
- Maximum height of the result image.public static java.awt.image.BufferedImage convertForDisplayIfNecessary(java.awt.image.BufferedImage image)
public static java.awt.image.BufferedImage convertForDisplayIfNecessary(java.awt.image.BufferedImage image, float threshold)
public static java.awt.image.BufferedImage rescale(java.awt.image.BufferedImage image, int maxWidth, int maxHeight, boolean enlargeIfNecessary, boolean highQuality8Bit)
maxWidth
- Maximum width of the result image.maxHeight
- Maximum height of the result image.enlargeIfNecessary
- if false and the image has smaller width and height than the
specified limit, then the image is not changed.highQuality8Bit
- if true thumbnails will be of higher quality, but rescaling will take
longer and the image will be converted to 8 bit.public static java.lang.String tryToFigureOutFileTypeOf(ch.systemsx.cisd.base.io.IRandomAccessFile handle)
gif, jpg, png, tif
.handle
- IRandomAccessFile
which supports marking.null
if file type couldn't be figured out.public static boolean isTiff(java.lang.String fileTypeOrNull)
true
if the fileTypeOrNull is a tiff file.public static boolean isJpeg(java.lang.String fileTypeOrNull)
true
if the fileTypeOrNull is a jpeg file.public static boolean isPng(java.lang.String fileTypeOrNull)
true
if the fileTypeOrNull is a png file.public static boolean isGif(java.lang.String fileTypeOrNull)
true
if the fileTypeOrNull is a gif file.