// BufferedImage to raw bytes
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
...

// O P E N
ByteArrayOutputStream baos = new ByteArrayOutputStream( 1000 );

// W R I T E
ImageIO.write( aBufferedImage, "jpeg" /* "png" "jpeg" ... format desired */,
           baos );

// C L O S E
baos.flush();
byte[] resultImageAsRawBytes = baos.toByteArray();

baos.close();