try{
File file = new File("C:\photo.jpg');
BufferedImage bufferedImg = ImageIO.read(file);
}
catch(IOException ioe)
{
System.exit(0);
}
You can easily manipulate BufferedImage instances.You can call setRGB(),getRGB() methods to set or get Red Green Blue parts in pixel color.
After read image to bufferedImg i need to get pixels so lets do it:
final int imwidth = bufImg.getWidth(null);
final int imheight = bufImg.getHeight(null);
for(int i=0; i < imheight;i++)
{
for(int j=0; j< imwidth;j++)
{
argb = getARGBs(j,i);
//do sth with Red Green Blue parts of a pixel color.
}
}
//Get Alpha Red Green Blue parts of a pixel color.
public int [] getARGBs(int x,int y)
{
int [] argbs = new int[4];
argbs[0] = (bufImg.getRGB(x,y) >> 24) & 0xff;//alpha
argbs[1] = (bufImg.getRGB(x,y) >> 16) & 0xff;//red
argbs[2]=(bufImg.getRGB(x,y) >> 8) & 0xff;//green
argbs[3] =(bufImg.getRGB(x,y)) & 0xff;//blue
return argbs;
}
No comments:
Post a Comment