74 lines
1.8 KiB
Java
74 lines
1.8 KiB
Java
import java.awt.*;
|
|
import java.io.*;
|
|
import java.awt.image.BufferedImage;
|
|
|
|
public class LectureFichier {
|
|
|
|
private BufferedImage image;
|
|
|
|
public LectureFichier() {
|
|
try {
|
|
BufferedReader lecture = new BufferedReader(new FileReader("image.xpm"));
|
|
|
|
try {
|
|
for (int i = 0; i != 3; i++) {
|
|
lecture.readLine();
|
|
}
|
|
|
|
String infos = lecture.readLine();
|
|
infos = infos.replaceAll("\"", "");
|
|
String[] infosTab = infos.split(" ");
|
|
for (String info : infosTab) {
|
|
System.out.println(info);
|
|
}
|
|
this.image = new BufferedImage(Integer.parseInt(infosTab[1]), Integer.parseInt(infosTab[2]), BufferedImage.TYPE_3BYTE_BGR);
|
|
|
|
char[] caracteres = new char[15];
|
|
Color[] couleurs = new Color[15];
|
|
|
|
for (int i = 0; i != Integer.parseInt(infosTab[2]); i++) {
|
|
String ligne = lecture.readLine();
|
|
caracteres[i] = ligne.charAt(1);
|
|
|
|
int[] rgb = {
|
|
Integer.parseInt(ligne.substring(6,8), 16),
|
|
Integer.parseInt(ligne.substring(8,10), 16),
|
|
Integer.parseInt(ligne.substring(10,12), 16)
|
|
};
|
|
|
|
couleurs[i] = new Color(rgb[0], rgb[1], rgb[2]);
|
|
|
|
}
|
|
|
|
lecture.readLine();
|
|
|
|
for (int i = 0; i != Integer.parseInt(infosTab[1]); i++) {
|
|
String ligne = lecture.readLine().replaceAll("\"", "");
|
|
ligne = ligne.substring(0, ligne.length()-1);
|
|
|
|
for (int j = 0; j != Integer.parseInt(infosTab[0]); j++) {
|
|
for (int k = 0; k != caracteres.length; k++) {
|
|
if (caracteres[k] == ligne.charAt(j)) {
|
|
this.image.setRGB(i, j, couleurs[k].getRGB());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e2) {
|
|
System.err.println("Erreur d'écriture");
|
|
}
|
|
|
|
try {
|
|
lecture.close();
|
|
} catch (IOException e3) {
|
|
System.err.println("Erreur de fermeture");
|
|
}
|
|
} catch (IOException e1) {
|
|
System.err.println("Erreur d'ouverture");
|
|
}
|
|
}
|
|
|
|
public BufferedImage getImage() {
|
|
return this.image;
|
|
}
|
|
} |