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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| public class LectureImage extends JPanel
{
public URL url;
public ArrayList teinte=new ArrayList();
public Graphics g;
public LectureImage(URL url)
{
this.url=url;
}
public void Connection()
{
try
{
URLConnection urlC= url.openConnection();
System.out.println(url);
//Accès au toolkit
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
//lecture de l'image
Image image = toolkit.getImage(url);
//On s'assure que l'image est complètement chargée
image = new ImageIcon(image).getImage();
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_RGB );
g = bufferedImage.createGraphics();
g.drawImage(image,0,0,null);
g.dispose();
//Lecture de tous les pixels
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
int[] rgbs = new int[w*h];
//On crée l'espace neccessaire
bufferedImage.getRGB(0,0,w,h,rgbs,0,w);
boolean ajout=true;
float testDoublon;
//parcours de mon tableau de pixels
for(int i=1;i<rgbs.length-1;i++)
{
int rouge = (rgbs[i-1] >>16 ) & 0xFF;
int vert = (rgbs[i-1] >> 8 ) & 0xFF;
int bleu = rgbs[i-1] & 0xFF;
//permet de récupérer directement la teinte d'un pixel
testDoublon = (Color.RGBtoHSB(rouge,vert,bleu,null))[0];
int j=1;
boolean ajouter=true;
//permet de tester que je n'ai pas de doublons dans les teintes
while(j<teinte.size()&&ajouter==true)
{
if((int)(testDoublon*1000)==(int)(((Float)teinte.get(j)).floatValue()*1000))
{
ajouter=false;
}
j++;
}
if(ajouter)
{
teinte.add(new Float(testDoublon));
}
}
this.paintComponent(g);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int largeurBarre=1;
Graphics2D g2d=(Graphics2D)g;
g2d.scale(5,-5);
g2d.translate(0,-110);
for(int i=1;i<=teinte.size();i++)
{
g2d.setColor(Color.getHSBColor(((Float)teinte.get(i-1)).floatValue(),1,1));
g2d.fillRect((i-1)*largeurBarre,0,largeurBarre,(int)(((Float)teinte.get(i-1)).floatValue()*100));
}
}
} |
Partager