Class ImageUtils
java.lang.Object
io.github.palexdev.imcache.utils.ImageUtils
Utility class for handling various image-related operations.
Note: ImCache
saves images on the disk with a custom format which contains the necessary data to reload them back with
the same id as when it was requested.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ImImage
deserialize
(File file) Deserializes the given file to anImImage
object only if the format version matchesFILE_FORMAT_VERSION
.static void
Serializes the givenImImage
object to the given file.static byte[]
Given an image as a generic type, converts it to a byte array.static BufferedImage
Given an image as a generic type, converts it to aBufferedImage
object.static InputStream
Given an image as a generic type, converts it to anInputStream
object.
-
Field Details
-
FILE_FORMAT_VERSION
public static final byte FILE_FORMAT_VERSION- See Also:
-
-
Method Details
-
serialize
Serializes the givenImImage
object to the given file.- Throws:
IOException
-
deserialize
Deserializes the given file to anImImage
object only if the format version matchesFILE_FORMAT_VERSION
.- Throws:
IOException
-
toBytes
Given an image as a generic type, converts it to a byte array.
Three types are currently supported:
- A byte array returns data as is
- A
BufferedImage
object is converted usingImageIO
and the given format, seeImageIO.write(RenderedImage, String, OutputStream)
. - An
InputStream
object is converted to a byte array usingInputStream.readAllBytes()
.
For other types or a
null
object, an empty array is returned. -
toImage
Given an image as a generic type, converts it to a
BufferedImage
object.Three types are currently supported:
- A
BufferedImage
object returns data as is. - A byte array is converted using
ImageIO.read(InputStream)
. - An
InputStream
object is converted to aBufferedImage
object usingImageIO.read(InputStream)
.
For other types or a
null
object,null
is returned. - A
-
toStream
Given an image as a generic type, converts it to an
InputStream
object.Three types are currently supported:
- An
InputStream
object returns data as is. - A byte array is converted to an
InputStream
object usingByteArrayInputStream
. - A
BufferedImage
object is converted to anInputStream
object usingByteArrayInputStream
andImageIO.write(RenderedImage, String, OutputStream)
.
For other types or a
null
object, an emptyInputStream
is returned. - An
-