public class ImageIOExt extends Object
Currently implemented optimizations:
MemoryCacheImageOutputStream
or a FileCacheImageOutputStream
based on a image size threshold
Constructor and Description |
---|
ImageIOExt() |
Modifier and Type | Method and Description |
---|---|
static <T extends ImageReaderWriterSpi> |
allowNativeCodec(String format,
Class<T> category,
boolean allowed)
Allows or disallows native acceleration for the specified image format.
|
static ImageInputStream |
createImageInputStream(Object input)
Returns a
ImageOutputStream suitable for writing on the specified input |
static ImageOutputStream |
createImageOutputStream(RenderedImage image,
Object destination)
Builds a
ImageOutputStream writing to destination , based on logic that
involves the image size |
static File |
getCacheDirectory()
Returns the cache directory used by ImageIOExt, either the manually configured one, or the
result of calling
ImageIO.getCacheDirectory() |
static Long |
getFilesystemThreshold()
The threshold at which the class will flip from
MemoryCacheImageOutputStream to
FileCacheImageOutputStream . |
static ImageInputStreamSpi |
getImageInputStreamSPI(Object input)
Get a proper
ImageInputStreamSpi instance for the provided Object input
without trying to create an ImageInputStream . |
static ImageInputStreamSpi |
getImageInputStreamSPI(Object input,
boolean streamCreationCheck)
Get a proper
ImageInputStreamSpi instance for the provided Object input. |
static ImageReader |
getImageioReader(ImageInputStream inStream)
Look for an
ImageReader instance that is able to read the provided ImageInputStream , which must be non null. |
static boolean |
isCLibAvailable()
Tells me whether or not the native libraries for JAI/ImageIO are active or not.
|
static RenderedImage |
read(Object input)
Reads an image from the given input, working around some JDK reader issues.
|
static BufferedImage |
readBufferedImage(Object input)
Same as
read(Object) but ensures the result is a BufferedImage , eventually
transforming it if needs be. |
static void |
setCacheDirectory(File cache)
Sets the directory where cache files are to be created.
|
static void |
setFilesystemThreshold(Long filesystemThreshold)
Sets the memory/file usage threshold (or null to have the code fall back on ImageIO behavior)
|
public static ImageOutputStream createImageOutputStream(RenderedImage image, Object destination) throws IOException
ImageOutputStream
writing to destination
, based on logic that
involves the image sizeimage
- the image to be written on the destination (can be null)destination
- the destinationIOException
public static ImageInputStream createImageInputStream(Object input) throws IOException
ImageOutputStream
suitable for writing on the specified input
destination
- IOException
public static File getCacheDirectory()
ImageIO.getCacheDirectory()
public static void setCacheDirectory(File cache)
ImageIO.getCacheDirectory()
will be used as the valuecacheDirectory
- a File
specifying a directory.public static Long getFilesystemThreshold()
MemoryCacheImageOutputStream
to
FileCacheImageOutputStream
. If the in memory, uncompressed image size is lower than
the threshold a MemoryCacheImageOutputStream
will be returned, otherwise a FileCacheImageOutputStream
will be used insteadpublic static void setFilesystemThreshold(Long filesystemThreshold)
filesystemThreshold
- getFilesystemThreshold()
public static <T extends ImageReaderWriterSpi> void allowNativeCodec(String format, Class<T> category, boolean allowed)
Implementation note: the current implementation assume that JAI codec class name start with "CLib". It work for Sun's 1.0 implementation, but may change in future versions. If this method doesn't recognize the class name, it does nothing.
format
- The format name (e.g. "png").category
- ImageReaderSpi.class
to set the reader, or ImageWriterSpi.class
to set the writer.allowed
- false
to disallow native acceleration.public static final ImageInputStreamSpi getImageInputStreamSPI(Object input)
ImageInputStreamSpi
instance for the provided Object
input
without trying to create an ImageInputStream
.getImageInputStreamSPI(Object, boolean)
public static final ImageInputStreamSpi getImageInputStreamSPI(Object input, boolean streamCreationCheck)
ImageInputStreamSpi
instance for the provided Object
input.input
- the input object for which we need to find a proper ImageInputStreamSpi
instancestreamCreationCheck
- if true
, when a proper ImageInputStreamSpi
have been found for the provided input, use it to try creating an ImageInputStream
on top of the input.ImageInputStreamSpi
instance.public static boolean isCLibAvailable()
false
in case the JAI/ImageIO native libs are not in the path,
true
otherwise.public static ImageReader getImageioReader(ImageInputStream inStream)
ImageReader
instance that is able to read the provided ImageInputStream
, which must be non null.
In case no reader is found, null
is returned.
inStream
- an instance of ImageInputStream
for which we need to find a suitable
ImageReader
.ImageReader
or null
if one cannot be
found.public static RenderedImage read(Object input) throws IOException
input
- A non null image source, like a File
, URL
, or InputStream
IOException
public static BufferedImage readBufferedImage(Object input) throws IOException
read(Object)
but ensures the result is a BufferedImage
, eventually
transforming it if needs be. Callers that can deal with RenderedImage
should use the
other method for efficiency sake.IOException
Copyright © 1996–2019 Geotools. All rights reserved.