public static byte[] bufferedImageToJPGByteArray(BufferedImage image) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ImageIO.write(image, "jpg", baos);
            //baos.flush();
            byte[] imageInByte = baos.toByteArray();
            //baos.close();
            return imageInByte;
        } catch (IOException ex) {
            Logger.getLogger(PHATImageUtils.class.getName()).log(Level.SEVERE, "bufferedImageToByteArray", ex);
        }
        return null;
    }
public static byte [ ] bufferedImageToJPGByteArray ( BufferedImage image ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { ImageIO . write ( image , "jpg" , baos ) ; byte [ ] imageInByte = baos . toByteArray ( ) ; return imageInByte ; } catch ( IOException ex ) { Logger . getLogger ( PHATImageUtils . class . getName ( ) ) . log ( Level . SEVERE , "bufferedImageToByteArray" , ex ) ; } return null ; }
TODO Optimizar la conversion!!