Hello:
I wanna use an image on java and get it's histogram. The thing is that I have a class called ImageHandler:
Code:
public class ImageHandler
{
public int[] pixels; private int iw, ih; private Image img; private PixelGrabber ptr; private ColorModel modelo;
public ImageHandler(Image img)
{
this.img = img;
iw = 10;//img.getWidth(null);
ih = 10;//img.getHeight(null);
pixels = new int[iw*ih];
ptr = new PixelGrabber(img, 0, 0, iw, ih, pixels, 0, iw);
try{
ptr.grabPixels();
}
catch(Exception e){}
modelo = ptr.getColorModel();
pixels = (int[])ptr.getPixels();
}// constructor
}// class
Then I take the image in an Applet as follows
Code:
public class Imagenes extends JApplet
{
ImageHandler imgHandler;
Image image;
Label l;
public void init()
{
image = getImage(getDocumentBase(), "1.gif");
imgHandler = new ImageHandler(image, 16);
l.setText("The content of pixel 1 is:" + imgHandler.pixels[0])
}
}//class
The Label l only shows negative numbers as -1323, -1, and 0's. any idea of why?
also you see I've commented the lines on iw and ih at Handler class because they will only generate an array of size 0............. but I did ask for the size right?
Thanks a lot!!!