我需要知道如何从java中加载的图像中获取字节数组。 BufferedImage似乎不提供任何产生字节数组的方法,那么我该怎么用?
答案 0 :(得分:2)
BufferedImage bufferedImage; //assumed that you have created it already
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage,"jpg", byteStream);
byte[] byteArray = byteStream.toByteArray();