- #1
ohaited
- 24
- 1
Greetings!
Hey guys, I need help on how can I get pixel value of an image with pixels more than 100px (10x10).
Here the code that I execute in order to get the pixel value
Actually I've tried this code for an image with 100px (10x10). And the value that I've got is quite good. But if I try with an image more than 100px it will not produce any output.
The only output I receive as i attached below
as in the link here
Hope you guys can help me out. Thank you in advance
Hey guys, I need help on how can I get pixel value of an image with pixels more than 100px (10x10).
Here the code that I execute in order to get the pixel value
Java:
try{
File f = new File ("input image location");
BufferedImage img = ImageIO.read(f);
}catch(IOException e){
System.out.println(e);
}
//get image width and height
int width = img.getWidth();
int height = img.getHeight();
int count=0;
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
count++;
//get pixel value
Color c = new Color(img.getRGB(j, i));
int p = img.getRGB(j, i);
//get alpha
int a = (p >> 24) & 0xff;
//get red
int r = (p >>16) & 0xff;
//get green
int g = (p >> 8) & 0xff;
//get blue
int b = (p >>0) & 0xff;
System.out.print("No. "+count);
System.out.println("Value of Alpha: "+a+ " Value of Red: "+r+" Value of Green: "+g+" Value of Blue: "+b+"");
p = (a<<24) | (r<<16) | (g<<8) | b;
System.out.println("Value of Pixel in Binary Presentation"+p);
img.setRGB(j, i, p);
try{
f = new File("output image location");
ImageIO.write(img, "png", f);
}catch(IOException e){
System.out.println(e);
}
}
}
The only output I receive as i attached below
as in the link here
Hope you guys can help me out. Thank you in advance
Last edited by a moderator: