get Black Image BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

get Black Image BufferedImage

Demo Code


//package com.java2s;
import java.awt.Color;
import java.awt.image.BufferedImage;

public class Main {
    public static void main(String[] argv) throws Exception {
        int width = 2;
        int height = 2;
        System.out.println(getBlackImage(width, height));
    }/*w w w. ja  v a2  s.  c  o  m*/

    public static BufferedImage getBlackImage(int width, int height) {
        BufferedImage image = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_ARGB);

        for (int i = 0; i < width - 1; i++) {
            for (int j = 0; j < height - 1; j++) {
                image.setRGB(i, j, Color.black.getRGB());
            }
        }

        return image;
    }
}

Related Tutorials