Package org.geotools.image.io
Class ImageIOExt
Object
ImageIOExt
Provides an alternative source of image input and output streams that uses optimized behavior.
Currently implemented optimizations:
- wrap an OutputStream into a
MemoryCacheImageOutputStream
or aFileCacheImageOutputStream
based on a image size threshold
- Since:
- 2.7.2
- Author:
- Andrea Aime - GeoSolutions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ImageReaderWriterSpi>
voidallowNativeCodec
(String format, Class<T> category, boolean allowed) Deprecated.static ImageInputStream
createImageInputStream
(Object input) Returns aImageOutputStream
suitable for writing on the specifiedinput
static ImageOutputStream
createImageOutputStream
(RenderedImage image, Object destination) Builds aImageOutputStream
writing todestination
, based on logic that involves the image sizestatic File
Returns the cache directory used by ImageIOExt, either the manually configured one, or the result of callingImageIO.getCacheDirectory()
static Long
The threshold at which the class will flip fromMemoryCacheImageOutputStream
toFileCacheImageOutputStream
.static final ImageInputStreamSpi
getImageInputStreamSPI
(Object input) Get a properImageInputStreamSpi
instance for the providedObject
input without trying to create anImageInputStream
.static final ImageInputStreamSpi
getImageInputStreamSPI
(Object input, boolean streamCreationCheck) Get a properImageInputStreamSpi
instance for the providedObject
input.static ImageReader
getImageioReader
(ImageInputStream inStream) Look for anImageReader
instance that is able to read the providedImageInputStream
, which must be non null.static RenderedImage
Reads an image from the given input, working around some JDK reader issues.static BufferedImage
readBufferedImage
(Object input) Same asread(Object)
but ensures the result is aBufferedImage
, 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)
-
Constructor Details
-
ImageIOExt
public ImageIOExt()
-
-
Method Details
-
createImageOutputStream
public static ImageOutputStream createImageOutputStream(RenderedImage image, Object destination) throws IOException Builds aImageOutputStream
writing todestination
, based on logic that involves the image size- Parameters:
image
- the image to be written on the destination (can be null)destination
- the destination- Throws:
IOException
-
createImageInputStream
Returns aImageOutputStream
suitable for writing on the specifiedinput
- Throws:
IOException
-
getCacheDirectory
Returns the cache directory used by ImageIOExt, either the manually configured one, or the result of callingImageIO.getCacheDirectory()
-
setCacheDirectory
Sets the directory where cache files are to be created. If set to null (the default value)ImageIO.getCacheDirectory()
will be used as the value- Parameters:
cache
- aFile
specifying a directory.
-
getFilesystemThreshold
The threshold at which the class will flip fromMemoryCacheImageOutputStream
toFileCacheImageOutputStream
. If the in memory, uncompressed image size is lower than the threshold aMemoryCacheImageOutputStream
will be returned, otherwise aFileCacheImageOutputStream
will be used instead -
setFilesystemThreshold
Sets the memory/file usage threshold (or null to have the code fall back on ImageIO behavior)- See Also:
-
allowNativeCodec
@Deprecated public static <T extends ImageReaderWriterSpi> void allowNativeCodec(String format, Class<T> category, boolean allowed) Deprecated.Native acceleration is no longer supported, please stop using this method -
getImageInputStreamSPI
Get a properImageInputStreamSpi
instance for the providedObject
input without trying to create anImageInputStream
.- See Also:
-
getImageInputStreamSPI
public static final ImageInputStreamSpi getImageInputStreamSPI(Object input, boolean streamCreationCheck) Get a properImageInputStreamSpi
instance for the providedObject
input.- Parameters:
input
- the input object for which we need to find a properImageInputStreamSpi
instancestreamCreationCheck
- iftrue
, when a properImageInputStreamSpi
have been found for the provided input, use it to try creating anImageInputStream
on top of the input.- Returns:
- an
ImageInputStreamSpi
instance.
-
getImageioReader
Look for anImageReader
instance that is able to read the providedImageInputStream
, which must be non null.In case no reader is found,
null
is returned.- Parameters:
inStream
- an instance ofImageInputStream
for which we need to find a suitableImageReader
.- Returns:
- a suitable instance of
ImageReader
ornull
if one cannot be found.
-
read
Reads an image from the given input, working around some JDK reader issues. At the time of writing, this applies a work around for PNGs with RGB (no alpha) and a transparent color configured in the header, that the JDK reader cannot handle.- Parameters:
input
- A non null image source, like aFile
,URL
, orInputStream
- Returns:
- A image
- Throws:
IOException
-
readBufferedImage
Same asread(Object)
but ensures the result is aBufferedImage
, eventually transforming it if needs be. Callers that can deal withRenderedImage
should use the other method for efficiency sake.- Returns:
- A image
- Throws:
IOException
-