How to convert Java Image into JPEG array of bytes?
-
24-09-2019 - |
Question
Is there a way to convert a Java Image, encode it into JPEG (but not saving it to a file), and store it as an array of bytes? (byte[]) I need the JPEG-encoded image as an array of bytes.
Solution
ImageIO
has a number of methods for reading and writing images.
For writing to array of bytes, you can write to ByteArrayOutputStream
. And then call toByteArray[]
of the stream object to obtain the byte array.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow