public static byte[] toByteArray(BufferedImage image, String format) {

		byte[] bytes = null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		try {
			ImageIO.write(image, format, baos);
			bytes = baos.toByteArray();
		} catch (IOException e) {
			throw new WebcamException(e);
		} finally {
			try {
				baos.close();
			} catch (IOException e) {
				throw new WebcamException(e);
			}
		}

		return bytes;
	}
public static byte [ ] toByteArray ( BufferedImage image , String format ) { byte [ ] bytes = null ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { ImageIO . write ( image , format , baos ) ; bytes = baos . toByteArray ( ) ; } catch ( IOException e ) { throw new WebcamException ( e ) ; } finally { try { baos . close ( ) ; } catch ( IOException e ) { throw new WebcamException ( e ) ; } } return bytes ; }
Convert {@link BufferedImage} to byte array.

@param image the image to be converted
@param format the output image format
@return New array of bytes