Q:

Finding the color at coordinates in a PNG image in Java

With a URL of a PNG image (or the data at that url, in String form), how could one use Java to find the RGB (or similar) value at a set of coordinates?
Thanks in advance!

A:

This example should have all you need:

http://www.daniweb.com/software-development/java/threads/114513

To cite the relevant part of the thread:
File inputFile = new File("image.png");
BufferedImage bufferedImage = ImageIO.read(inputFile);
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight(null);

//Get Pixels
int [] rgbs = new int[w*h];
bufferedImage.getRGB(0, 0, w, h, rgbs, 0, w); //Get all pixels

and then to get a particular pixel, see the docs:

http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html#getRGB(int,%20int,%20int,%20int,%20int%91%93,%20int,%20int)

i.e.:
int pixel = rgbs[offset + (y-startY)*scansize + (x-startX)];

If you just want one pixel, you can use getRGB(x, y):

http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html#getRGB(int,%20int)

i.e.:
int pixel = bufferedImage.getRGB(x, y);

