1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public static void Main_Color(String path_Image) throws IOException{
int cpt=0;
listcpt.add(cpt);
System.out.println(listcpt);
imgglobal = ImageIO.read(new File("C:\\Users\\guill\\"+path_Image));
for(int a =0; a< imgglobal.getWidth();a++){
for(int b =0; b< imgglobal.getHeight(); b++){
int p = imgglobal.getRGB(a, b);
int r = (p>>16)&0xff;
int g = (p>>8)&0xff;
int bl = p&0xff;
listpx.add(r);
listpx.add(g);
listpx.add(bl);
System.out.println(listpx);
for(int i =0; i< imgglobal.getWidth();i++){
for(int j =0; j< imgglobal.getHeight(); j++){
p = imgglobal.getRGB(i, j);
r = (p>>16)&0xff;
g = (p>>8)&0xff;
bl = p&0xff;
System.out.println("ok");
if(r==listpx.get(0) && g==listpx.get(1) && bl==listpx.get(2)){
cpt++;
System.out.println("+1");
}
}
}
if(cpt > listcpt.get(0)){
listcpt.clear();
listcpt.add(cpt);
listpxSave = listpx;
}
cpt = 0;
listpx.clear();
}
}
System.out.println("The main color is : " + listpxSave);
System.out.println("This color appears " + listcpt.get(0)+ " times");
} |
Partager