get Image As Bytes - Java 2D Graphics

Java examples for 2D Graphics:Image Load

Description

get Image As Bytes

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Main {
    public static byte[] getImageAsBytes(BufferedImage imgimage,
            String encoding) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ImageIO.write(imgimage, "jpeg", out);
        return out.toByteArray();
    }/*  w ww. j  a v a 2 s.  com*/
}

Related Tutorials