Get and Set Pixels in a Buffered Image in Java

Description

The following code shows how to get and Set Pixels in a Buffered Image.

Example


/*  www. j  ava2s  . c  o m*/
import java.awt.image.BufferedImage;

public class Main {
  public static void main(String[] argv) throws Exception {

    BufferedImage bufferedImage = new BufferedImage(200, 200,
        BufferedImage.TYPE_INT_RGB);

    int rgb = bufferedImage.getRGB(1, 1);

    int w = bufferedImage.getWidth(null);
    int h = bufferedImage.getHeight(null);
    int[] rgbs = new int[w * h];
    bufferedImage.getRGB(0, 0, w, h, rgbs, 0, w);

    rgb = 0xFF00FF00; // green
    bufferedImage.setRGB(1, 1, rgb);
  }
}




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform