Hi,
I am writing a code to get pixels value of the entire image and store it into a array.
But i am facing the problems, as outlined below.
I would be grateful if someone could help me in sorting this out..
Cheers :)
File inputFile = new File("one.jpg");
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
for(int i=0;i<w*h;i++)
System.out.println("rgbs["+i+"]= "+rgbs[i]);
//when i printed this, I was expecting pixel values
//but I got negative values... :|
//Set Pixels
int rgb = 0xFF00FF00; // green
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
bufferedImage.setRGB(j,k, rgb);
//Instead of setting the pixels to green,
//it is instead set to Gray... :confused:
http://pastebin.stonekeep.com/1748
(if you want to see the syntax highlighting...