I am new in python n java. I've given the task at my class for showing pixel array image from an image. Please help me?? Thanks
3 Answers
Are you trying to get a 2D array if each pixel color? In the Java BufferedImage class, there is the method:
getRGB(int x, int y)
Therefore, you could just loop through each pixel and add it to your array, like this:
int[][] array = new int[img.getWidth()][img.getHeight()];
for (int i = 0; i < img.getWidth(); i++) {
for (int j = 0; i < img.getHeight(); j++) {
array[i][j] = img.getRGB(i, j);
}
}
This will give you a 2D array of the RGB value of each pixel.
1 Comment
irham
Thanks very much. it's really I am need for doing my homework.. :D
You might study this Java example that uses the graphics context's drawImage() to enlarge an image and report the color of each pixel.
Comments
You might want to look in to the Python Image Library (PIL), I recommend it.
2 Comments
irham
where can i download PIL for python 3? I never found it
Jeffrey Greenham
I don't think they support it yet