code: 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;
      }
docs: TODO Optimizar la conversion!!