Package com.iizix.image
Class CachedImage
java.lang.Object
com.iizix.image.CachedImage
The cached image class contains a loaded image in memory and can be used to perform various operations on it.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsConstructorDescriptionCachedImage(File file) Loads an image from a File without keeping the file data.CachedImage(File file, boolean keepFileData) Loads an image from a File.Method Summary
Modifier and TypeMethodDescriptionGets the buffered image.byte[]getData()Gets a copy of the original (file) data.Gets the file extension.Gets the original file name.getSize()Gets the image size.Generates a new cached image scaled to the request dpr (100% = 1d = 1 DPR, 200% = 2 DPR, etc.).Generates a new cached image thumbnail that has the maximum width and height.voidWrites the image data to a file.
Constructor Details
CachedImage
Loads an image from a File without keeping the file data.An error is logged in the server in case of an exception not being a direct
{@link IOException}.- Parameters:
file- The file.- Throws:
FileNotFoundException- If the file is not found.IOException- For I/O errors (could also wrap e.g. OutOfMemoryError or other exceptions).
CachedImage
Loads an image from a File.An error is logged in the server in case of an exception not being a direct
{@link IOException}.- Parameters:
file- The file.keepFileData- Flag to keep the original file data (please note that this requires more memory).- Throws:
FileNotFoundException- If the file is not found.IOException- For I/O errors (could also wrap e.g. OutOfMemoryError or other exceptions).
Method Details
getBufferedImage
Gets the buffered image.- Returns:
- The buffered image.
getFileName
Gets the original file name.- Returns:
- The original file name.
getFileExtension
Gets the file extension.- Returns:
- The file extension without the "dot",
nullif none is found.
getSize
Gets the image size.- Returns:
- The size of the image.
getData
public byte[] getData()Gets a copy of the original (file) data.- Returns:
- The byte array, or
nullin case of an OutOfMemoryException or that the file data is not kept in this instance. An error is logged in the server in case of a problem.
writeTo
Writes the image data to a file. The data written is the cached data if present, otherwise the data from the buffered image.- Parameters:
file- The new file name, including a potential new file extension.- Throws:
IllegalArgumentException- If the file name does is not present.IOException- For I/O errors.
scale
Generates a new cached image scaled to the request dpr (100% = 1d = 1 DPR, 200% = 2 DPR, etc.).- Parameters:
dpr- The desired DPR.suffix- The suffix to append to the file name.- Returns:
- A new cached image.
- Throws:
IllegalArgumentException- If dpr is zero or negative.
scale
Generates a new cached image thumbnail that has the maximum width and height. The scaling factor is calculated to fit, i.e. the aspect/ratio of the image is kept.- Parameters:
maxWidth- The width.maxHeight- The height.- Returns:
- A new cached image.
- Throws:
IllegalArgumentException- If the width or height is less than 1.