BufferedImage to Bytes Java
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.
链接地址: http://www.djcxy.com/p/51836.html上一篇: window.fireEvent和window.dispatchEvent在IE8中都未定义
下一篇: BufferedImage字节Java