get Image From Data - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

get Image From Data

Demo Code


//package com.java2s;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage getImageFromData(int[][] imageData) {
        BufferedImage image = new BufferedImage(imageData.length,
                imageData[0].length, ColorSpace.TYPE_RGB);
        int width = image.getWidth();
        int height = image.getHeight();
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                image.setRGB(x, y, imageData[x][y]);
            }/*  w  ww.j  a  va2  s  .c  o  m*/
        }
        return image;
    }
}

Related Tutorials