R
Riri
I've found this code on sun web site, but, i don't quite understand what
public void handlesinglepixel(int x, int y, int pixel) does. What is stored
in the table of int[] returned by the method public int[] handlepixels(Image
img, int x, int y, int w, int h)?It seems that the values stored in that
table are the values of the pixels, i thought it would be RGBs values (int
for 0 to 255), but it's not.
Any idea?
Thanks
//Création du tableau pixel image et affichage
public void handlesinglepixel(int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
}
//Récupération des pixels
public int[] handlepixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return null;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return null;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
handlesinglepixel(x+i, y+j, pixels[j * w + i]);
}
}
return pixels;
}
public void handlesinglepixel(int x, int y, int pixel) does. What is stored
in the table of int[] returned by the method public int[] handlepixels(Image
img, int x, int y, int w, int h)?It seems that the values stored in that
table are the values of the pixels, i thought it would be RGBs values (int
for 0 to 255), but it's not.
Any idea?
Thanks
//Création du tableau pixel image et affichage
public void handlesinglepixel(int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
}
//Récupération des pixels
public int[] handlepixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return null;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return null;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
handlesinglepixel(x+i, y+j, pixels[j * w + i]);
}
}
return pixels;
}