hey i had started coding in java.I want to display the pixels format of image with the following code but i get errors...Can anyone suggest my code??
public void Pixelvalue(Image img){
int[] pixelss = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixelss, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}
for (int i = 0; i < w; i++) {
//handlesinglepixel(x+i, y+j, pixels[j * w + i]);
System.out.println(" pixelss[i]") ;
}
}
Errors:
Uncaught error fetching image:
java.lang.ArrayIndexOutOfBoundsException: 1
at java.awt.image.PixelGrabber.setPixels(PixelGrabber.java:599)
at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:97)
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:119)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
image fetch aborted or errored