Getting and Setting Pixels in a Buffered Image : Image « Advanced Graphics « Java






Getting and Setting Pixels in a Buffered Image

  

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);
  }
}

   
    
  








Related examples in the same category

1.Create an image that does not support transparency
2.Create an image that supports transparent pixels
3.Create an image that supports arbitrary levels of transparency
4.Creating a buffered image using Component.createImage().
5.Creating a Buffered Image from an Image
6.Drawing on a Buffered Image
7.If the buffered image supports transparency
8.Converting a Buffered Image (BufferedImage) from an Image
9.Scaling a Buffered Image
10.Shearing a Buffered Image
11.Translating a Buffered Image
12.Rotating a Buffered Image
13.Flipping a Buffered Image
14.Flip the image horizontally
15.Flip the image vertically and horizontally, equivalent to rotating the image 180 degrees
16.2D Image Draw
17.Transform image
18.Creating a Image Zoomer using Graphics2D
19.Gaussian Blur DemoGaussian Blur Demo
20.Intermediate ImagesIntermediate Images
21.Image reflectionImage reflection
22.Bloom DemoBloom Demo
23.Box Blur DemoBox Blur Demo
24.Brightness Increase DemoBrightness Increase Demo
25.Blur an ImageBlur an Image
26.Blur our image: Blur means an unfocused image
27.A reflected image: effect makes an illusion as if the image was reflected in water
28.Enlarge Image With AnimationEnlarge Image With Animation
29.Image ZoomingImage Zooming
30.Simple image handling and drawing interactionSimple image handling and drawing interaction
31.Unsharp Mask DemoUnsharp Mask Demo
32.Create a grayscale image with Java 2D tools
33.A 3x3 kernel that embosses an image.
34.A 3x3 kernel that blurs an image.
35.A 3x3 kernel that sharpens an image.
36.Embossing a Buffered Image
37.Brighten the image by 30%
38.Darken the image by 10%
39.Extend RGBImageFilter to create ColorFilter class
40.Extend RGBImageFilter to create AlphaFilter class
41.Enlarging an image by pixel replication
42.Shrinking an image by skipping pixels