Get a JPEG representation of a JPEG image

I need to know how to get a byte array from an uploaded image in java. BufferedImage doesn't seem to provide any methods that produce a byte array, so what am I using?

+2


source to share


1 answer


BufferedImage bufferedImage; //assumed that you have created it already
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage,"jpg", byteStream);
byte[] byteArray = byteStream.toByteArray();

      



+2


source







All Articles