Kanishka Dilshan
Kanishka Dilshan

Reputation: 734

Accessing Image pixel by pixel in Java

Is there any inbuilt java API or class library for accessing pixels in a given image? What I am planning to do is search one image inside another image. For example : img1 is 24x24px , img2 is 1024x768px assume that a symbol, similar to img1 may exists in img2 . Now I want to get X and Y coordinates of the symbol which is similar to the img1.

Upvotes: 4

Views: 2215

Answers (3)

You can use the getRGB(...) method in the Java BufferedImage class.

Upvotes: 4

Alexis Dufrenoy
Alexis Dufrenoy

Reputation: 11966

If you have a java.awt.image.BufferedImage, you can call getRGB(), which returns a array of ints containing the color values of each pixel.

If you Image is not an instance of BufferedImage, you can use java.awt.image.PixelGrabber to get the same result, using the setPixels() method.

Upvotes: 2

Jesper
Jesper

Reputation: 206956

Yes, there is, if you have your image as a BufferedImage then use the getRGB(int x, int y) method to get the value of the pixel at the position (x, y).

See the API documentation of java.awt.image.BufferedImage.

Upvotes: 6

Related Questions