Ciao,
ti ringrazio infinitamente..
ho realizzato un programma utilizzando praticamente il tuo codice, (Ho solo sostituito con un Integer il Char che usavi tu). Ora però il compilatore mi da questo errore:
File: C:\Programmi\ImageJ\plugins\GIF\Gif.java [line: 66]
Error: C:\Programmi\ImageJ\plugins\GIF\Gif.java:66: non-static variable this cannot be referenced from a static context
File: C:\Programmi\ImageJ\plugins\GIF\Gif.java [line: 91]
Error: C:\Programmi\ImageJ\plugins\GIF\Gif.java:91: non-static variable this cannot be referenced from a static context
--------------[line: 66]
Ti posto il codice:
codice:
public static ImageProcessor CompressRGBAdaptive(ImageProcessor ip,int nx,int ny,int pal,int numCol)
{
int array[] = new int[4];
HashMap<Integer,ColorCounter> map = new HashMap<Integer,ColorCounter> ();
for(int x = 0;x<nx;x++) {
for(int y=0;y<ny;y++) {
array = ip.getPixel(x,y,array);
Integer i = (array[0] << 16)+(array[1] << 8)+(array[2]);
ColorCounter cc = map.get(i);
if (cc == null)
{
cc = new ColorCounter (i);
map.put (i, cc);
}
cc.increment ();
}
}
// crea lista
ArrayList<ColorCounter> list = new ArrayList<ColorCounter> (map.size ());
for (Integer c : map.keySet ())
list.add (map.get (c));
// ordina lista
Collections.sort (list, new CounterComparator ());
// stampa lista
for (ColorCounter cc : list)
IJ.write("'" + cc.getColor () + "' -> " + cc.getPixel ());
return ip;
}
class CounterComparator implements Comparator<ColorCounter>
{
public int compare (ColorCounter o1, ColorCounter o2)
{
int c1 = o1.getPixel();
int c2 = o2.getPixel();
// compara i due contatori
return c1 < c2 ? +1 : c1 > c2 ? -1 : 0;
}
}
class ColorCounter {
private int numPixel,color;
public ColorCounter(int color){
this.color=color;
}
public int getPixel() {
return this.numPixel;
}
public int getColor() {
return this.color;
}
public void increment() {
numPixel++;
}
}
Che tipo di errore ho commesso?
Gli errori sono sulle righe che ho messo in grassetto che comunque riporto:
codice:
cc = new ColorCounter (i);
Collections.sort (list, new CounterComparator ());
Grazie
Giovanni