Java BufferedImage to Byte Array toByteArray(BufferedImage img, String imageFileType)

Here you can find the source of toByteArray(BufferedImage img, String imageFileType)

Description

to Byte Array

License

Open Source License

Declaration

private static byte[] toByteArray(BufferedImage img, String imageFileType) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt
 ******************************************************************************/

import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import javax.imageio.ImageIO;

public class Main {
    private static byte[] toByteArray(BufferedImage img, String imageFileType) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {/* w  w  w .ja  va  2  s. c om*/
            ImageIO.write(img, imageFileType, baos);
            return baos.toByteArray();
        } catch (Throwable e) {
            throw new RuntimeException();
        }
    }
}

Related

  1. toArrayByte(BufferedImage image)
  2. toByteArray(BufferedImage image)
  3. toByteArray(BufferedImage image, float quality)
  4. toByteArray(BufferedImage image, String extension)
  5. toByteArray(BufferedImage image, String formatName)
  6. toByteArray(BufferedImage org)
  7. toByteArray(final BufferedImage image, final String format)
  8. toByteArray(RenderedImage image)
  9. toByteBuffer(BufferedImage img)