This commit is contained in:
Simoes Lukas
2025-03-27 13:35:54 +01:00
parent 376861b608
commit fe693705bf
90 changed files with 1188 additions and 24 deletions

View File

@@ -0,0 +1,74 @@
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[0]), Integer.parseInt(infosTab[1]), 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 != ligne.length(); 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;
}
}