Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;

public class Main {
    public static byte[] getImage(final InputStream inputStream) {
        byte images[] = null;
        try {
            // final BufferedImage image = ImageIO.read(new File(
            // "d:\\images\\peacock.jpg"));

            final BufferedImage image = ImageIO.read(inputStream);

            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "jpeg", baos);

            // ImageIO.write(image, "jpeg", new File("D:\\images.jpeg"));
            images = baos.toByteArray();

        } catch (final Exception e) {
            e.printStackTrace();

        }
        return images;
    }
}