Here you can find the source of encodeJPEG(BufferedImage image)
Parameter | Description |
---|---|
image | the image to encode |
public static byte[] encodeJPEG(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class Main { /**/* ww w . j av a 2s . com*/ * Performs in-memory encoding of a BufferedImage to a byte array. * * @param image the image to encode * @return a newly allocated byte array that contains the encoded image */ public static byte[] encodeJPEG(BufferedImage image) { ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); try { ImageIO.write(image, "jpeg", resultStream); } catch (IOException e) { throw new Error(e); } return resultStream.toByteArray(); } }