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
MemoryCacheImageOutputStreamor aFileCacheImageOutputStreambased 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 ImageInputStreamcreateImageInputStream(Object input) Returns aImageOutputStreamsuitable for writing on the specifiedinputstatic ImageOutputStreamcreateImageOutputStream(RenderedImage image, Object destination) Builds aImageOutputStreamwriting todestination, based on logic that involves the image sizestatic FileReturns the cache directory used by ImageIOExt, either the manually configured one, or the result of callingImageIO.getCacheDirectory()static LongThe threshold at which the class will flip fromMemoryCacheImageOutputStreamtoFileCacheImageOutputStream.static final ImageInputStreamSpigetImageInputStreamSPI(Object input) Get a properImageInputStreamSpiinstance for the providedObjectinput without trying to create anImageInputStream.static final ImageInputStreamSpigetImageInputStreamSPI(Object input, boolean streamCreationCheck) Get a properImageInputStreamSpiinstance for the providedObjectinput.static ImageReadergetImageioReader(ImageInputStream inStream) Look for anImageReaderinstance that is able to read the providedImageInputStream, which must be non null.static RenderedImageReads an image from the given input, working around some JDK reader issues.static BufferedImagereadBufferedImage(Object input) Same asread(Object)but ensures the result is aBufferedImage, eventually transforming it if needs be.static voidsetCacheDirectory(File cache) Sets the directory where cache files are to be created.static voidsetFilesystemThreshold(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 aImageOutputStreamwriting 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 aImageOutputStreamsuitable 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- aFilespecifying a directory.
-
getFilesystemThreshold
The threshold at which the class will flip fromMemoryCacheImageOutputStreamtoFileCacheImageOutputStream. If the in memory, uncompressed image size is lower than the threshold aMemoryCacheImageOutputStreamwill be returned, otherwise aFileCacheImageOutputStreamwill 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 properImageInputStreamSpiinstance for the providedObjectinput without trying to create anImageInputStream.- See Also:
-
getImageInputStreamSPI
public static final ImageInputStreamSpi getImageInputStreamSPI(Object input, boolean streamCreationCheck) Get a properImageInputStreamSpiinstance for the providedObjectinput.- Parameters:
input- the input object for which we need to find a properImageInputStreamSpiinstancestreamCreationCheck- iftrue, when a properImageInputStreamSpihave been found for the provided input, use it to try creating anImageInputStreamon top of the input.- Returns:
- an
ImageInputStreamSpiinstance.
-
getImageioReader
Look for anImageReaderinstance that is able to read the providedImageInputStream, which must be non null.In case no reader is found,
nullis returned.- Parameters:
inStream- an instance ofImageInputStreamfor which we need to find a suitableImageReader.- Returns:
- a suitable instance of
ImageReaderornullif 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 withRenderedImageshould use the other method for efficiency sake.- Returns:
- A image
- Throws:
IOException
-