BufferedImage img = null;
int w, h;
int pixels[];
try {
img = ImageIO.read(new File("images/secret.jpg"));
w = img.getWidth();
h = img.getHeight();
pixels = new int[w * h];
img.getRGB(0, 0, w, h, pixels, 0, w);
System.out.println(img.getWidth() + " X " + img.getHeight());
System.out.println("R:" + ((pixels[0] >> 16) & 0xff) + " G:" + ((pixels[0] >> 8) & 0xff) + " B:" + (pixels[0] & 0xff));
} catch (IOException e) {
e.printStackTrace();
}
//Based on the sample code, it is really easy to see how to read RGB values from any image files.
5 comments:
Thank you for posting your information! I think it will help me in my project!! Have a great day.
Thanks you Junxian. This is a useful code for me.
Superb Code. It really helped me too much.
Thanks!
can you pls help us out for grabbing pixels in image and use those pixels to cut the image diagonally
can you pls tell how to convert pixel values to image
Post a Comment