Reputation: 734
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
Reputation: 8255
You can use the getRGB(...)
method in the Java BufferedImage
class.
Upvotes: 4
Reputation: 11966
If you have a java.awt.image.BufferedImage
, you can call getRGB()
, which returns a array of int
s 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
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