Java JPEG jpegFromImage(BufferedImage image)

Here you can find the source of jpegFromImage(BufferedImage image)

Description

jpeg From Image

License

Apache License

Declaration

public static byte[] jpegFromImage(BufferedImage image)
            throws IOException 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Main {
    public static byte[] jpegFromImage(BufferedImage image)
            throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(128000);
        javax.imageio.ImageIO.write(image, "jpg", bos);

        byte[] jpegBits = bos.toByteArray();
        bos.close();//from   w  w w.j  a v a2  s  .c  o  m
        return jpegBits;
    }
}

Related

  1. fixImageIOJpegBug(BufferedImage image)
  2. jpeg2BufferedImage(final byte[] jpegImage, final boolean bw)
  3. png2jpeg(File pngImage, File jpegFile)