Here you can find the source of encodeBufferedImageAsJPEG(BufferedImage bi)
Parameter | Description |
---|---|
bi | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] encodeBufferedImageAsJPEG(BufferedImage bi) throws IOException
//package com.java2s; /*/*from w ww .j a v a 2 s . com*/ * Orbit, a versatile image analysis software for biological image-based quantification. * Copyright (C) 2009 - 2016 Actelion Pharmaceuticals Ltd., Gewerbestrasse 16, CH-4123 Allschwil, Switzerland. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { /** * Stores BufferedImage as JPEG encoded bytestream * * @param bi * @return * @throws IOException */ public static byte[] encodeBufferedImageAsJPEG(BufferedImage bi) throws IOException { byte[] byteStream = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ImageIO.write(bi, "jpeg", baos); baos.flush(); byteStream = baos.toByteArray(); baos.close(); return byteStream; } }