update
This commit is contained in:
BIN
DEV.2.1/TP/TP11-Flux-octets/3./EcritureFichier.class
Normal file
BIN
DEV.2.1/TP/TP11-Flux-octets/3./EcritureFichier.class
Normal file
Binary file not shown.
108
DEV.2.1/TP/TP11-Flux-octets/3./EcritureFichier.java
Normal file
108
DEV.2.1/TP/TP11-Flux-octets/3./EcritureFichier.java
Normal file
@@ -0,0 +1,108 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class EcritureFichier {
|
||||
|
||||
private int r;
|
||||
private int g;
|
||||
private int b;
|
||||
|
||||
private int r2;
|
||||
private int g2;
|
||||
private int b2;
|
||||
|
||||
public EcritureFichier(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
System.out.println(r + " " + g + " " + b);
|
||||
try {
|
||||
for (int i = 0; i != 768; i++) {
|
||||
for (int j = 0; j != 1024; j++) {
|
||||
fichier.write(r);
|
||||
fichier.write(g);
|
||||
fichier.write(b);
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public EcritureFichier(int r, int g, int b, int r2, int g2, int b2) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.r2 = r2;
|
||||
this.g2 = g2;
|
||||
this.b2 = b2;
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
int choixR = r;
|
||||
int choixG = g;
|
||||
int choixB = b;
|
||||
|
||||
try {
|
||||
for (int l = 0; l != 8; l++) {
|
||||
for (int k = 0; k != 8; k++) {
|
||||
for (int i = 0; i != 768/8; i++) {
|
||||
for (int j = 0; j != 1024/8; j++) {
|
||||
fichier.write(choixR);
|
||||
fichier.write(choixG);
|
||||
fichier.write(choixB);
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
BIN
DEV.2.1/TP/TP11-Flux-octets/3./Main.class
Normal file
BIN
DEV.2.1/TP/TP11-Flux-octets/3./Main.class
Normal file
Binary file not shown.
21
DEV.2.1/TP/TP11-Flux-octets/3./Main.java
Normal file
21
DEV.2.1/TP/TP11-Flux-octets/3./Main.java
Normal file
@@ -0,0 +1,21 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
String chaineCouleur = args[0].replaceAll("#", "");
|
||||
Integer r = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(0, 2), 16));
|
||||
Integer g = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(2, 4), 16));
|
||||
Integer b = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(4, 6), 16));
|
||||
|
||||
if (args.length == 1) {
|
||||
EcritureFichier ecriture = new EcritureFichier(r, g, b);
|
||||
}
|
||||
|
||||
else if (args.length == 2) {
|
||||
String chaineCouleur2 = args[1].replaceAll("#", "");
|
||||
Integer r2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(0, 2), 16));
|
||||
Integer g2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(2, 4), 16));
|
||||
Integer b2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(4, 6), 16));
|
||||
System.out.println(r + "," + g + "," + b + " | " + r2 + "," + g2 + "," + b2);
|
||||
EcritureFichier ecriture2 = new EcritureFichier(r, g, b, r2, g2, b2);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user