Controle machine
This commit is contained in:
52
DEV2.1/TP11/01_Image/LectureFichier.java
Normal file
52
DEV2.1/TP11/01_Image/LectureFichier.java
Normal file
@@ -0,0 +1,52 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
public LectureFichier() {
|
||||
this.image = new BufferedImage(768, 1024, BufferedImage.TYPE_3BYTE_BGR);
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
Color couleur;
|
||||
|
||||
try {
|
||||
FileInputStream fichier = new FileInputStream("image.bin");
|
||||
|
||||
while(fichier.available() >= 3) {
|
||||
try {
|
||||
r = fichier.read();
|
||||
g = fichier.read();
|
||||
b = fichier.read();
|
||||
couleur = new Color(r, g, b);
|
||||
this.image.setRGB(i, j, couleur.getRGB());
|
||||
i++;
|
||||
if (i >= 768) {
|
||||
j++;
|
||||
i = 0;
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'accès");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
return this.image;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user