public static byte[] bufferedImageToByteArray(BufferedImage bufferedImage) {
	byte[] image = null;
	try {
	    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
		ImageIO.write(bufferedImage, "jpg", baos);
		baos.flush();
		image = baos.toByteArray();
	    }
	} catch (IOException ex) {
	    Logger.getLogger(ImageUtils.class.getName()).log(Level.SEVERE, null, ex);
	}
	return image;
    }