Here you can find the source of jpegFromImage(BufferedImage image)
public static byte[] jpegFromImage(BufferedImage image) throws IOException
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { public static byte[] jpegFromImage(BufferedImage image) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(128000); javax.imageio.ImageIO.write(image, "jpg", bos); byte[] jpegBits = bos.toByteArray(); bos.close();//from w w w.j a v a2 s .c o m return jpegBits; } }