Convert a BufferedImage to a Byte Array as JPEG


/ Published in: Java
Save to your folder(s)

i use it so save bufferedImages into a DB as Blob


Copy this code and paste it in your HTML
  1. public static byte[] bufferedImageToByteArray(BufferedImage img) throws ImageFormatException, IOException{
  2. JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
  3. encoder.encode(img);
  4. return os.toByteArray();
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.