public class TestImagesss {
public static void main(String[] args) {
int value[][]=getRGB(getImage("test.jpg"));
int valueR[][]=getR(getImage("test.jpg"));
}
//.... code below :}
The Code for Reading Image from File and getting RGB values separately :
public static BufferedImage getImage(String imageName) {
try {
File input = new File(imageName);
BufferedImage image = ImageIO.read(input);
return image;
} catch (IOException ie) {
System.out.println("Error:" + ie.getMessage());
}
return null;
}
public static int [][] getRGB(BufferedImage img) {
int w1 = img.getWidth();
int h1 = img.getHeight();
int value[][] = new int[w1][h1];
for (int i = 0; i < w1; i++) {
for (int j = 0; j < h1; j++) {
value[i][j] = img.getRGB(i, j); // store value
}
}
return value;
}
public static int [][] getR(BufferedImage img) {
int w1 = img.getWidth();
int h1 = img.getHeight();
int value;
int valueR[][] = new int[w1][h1];
for (int i = 0; i < w1; i++) {
for (int j = 0; j < h1; j++) {
value = img.getRGB(i, j); // store value
valueR[i][j] = getRed(value);
}
}
return valueR;
}
public static int [][] getG(BufferedImage img) {
//
return valueG;
}
public static int [][] getB(BufferedImage img) {
//
return valueB;
}
public static int [][] getA(BufferedImage img) {
//
return valueA;
}
public static int getAlpha(int rgb) {
return (rgb >> 24) & 0xFF;
}
public static int getRed(int rgb) {
return (rgb >> 16) & 0xFF;
}
public static int getGreen(int rgb) {
return (rgb >> 8) & 0xFF;
}
public static int getBlue(int rgb) {
return rgb & 0xFF;
}
how to print the RGB value?
ReplyDelete