Bonjour,
Voici un morceau de code pour lire des images :
private void recupImageData(String fileName){ System.out.println("Lecture image "+fileName); Image img = Toolkit.getDefaultToolkit().getImage(fileName); ImageIcon icon = new ImageIcon(img); sizeX = icon.getIconWidth(); sizeY = icon.getIconHeight(); int[] pixels = new int[(sizeX) * (sizeY)]; PixelGrabber pg = new PixelGrabber(img, 0, 0, sizeX, sizeY, pixels, 0, sizeX); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } for (int x = 0; x < sizeX; x++) { for(int y=0;y < sizeY; y++) { int c = pixels[y*sizeX+x]; int alpha = (c >> 24) & 0xff; int red = (c >> 16) & 0xff; int green = (c >> 8) & 0xff; int blue = c & 0xff; } /* et là tu recupères la couleur de ton point et en fait ce que tu veux.... (binarisation, niveaux de gris, création de mailles ...)*/ }
Ce code ne fonctionne pas avec tous les formats d'image.
|