I am trying to get the bytearray from a bufferedImage but the length of my ByteArrayOutputstream is always zero and I get no bytes. This is what I am doing
any ideas why this is not working
BufferedImage scaledPicture = .....
ByteArrayOutputStream baos = new ByteArrayOutputStream( );
ImageIO.write(scaledPicture, extension, baos);
baos.flush();
byte[] toByteArray = baos.toByteArray();
baos.close();
return toByteArray;
Any ideas?
What is the return value of ImageIO.write
? Does ImageIO.getImageWritersByFormatName
with your extension return at least 1 ImageWriter
? If not, then the format may not be supported.
Does the 'ImageIO.write(...)' call return true? If no, the JVM might be failing to find a writer of the appropriate format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With