This commit is contained in:
2023-04-27 11:27:11 +02:00
parent bfcbd64735
commit 93c00d1ed0
24 changed files with 483 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,41 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.io.*;
public class Imag extends JComponent{
private Image image;
public Imag(int width, int height, String path) throws IOException {
image = readFromFile(width, height, path);
setPreferredSize(new Dimension(width, height));
}
private Image readFromFile(int width, int height, String path) throws IOException {
FileInputStream input = new FileInputStream(path);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
for (int i = 0; i < height; i++){
for (int j = 0; j < width; j++){
int r = input.read();
int g = input.read();
int b = input.read();
int rgb = (r << 16 | (g << 8) | (b));
img.setRGB(j, i, rgb);
}
}
return img;
}
@Override
protected void paintComponent(Graphics pinceau) {
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
Graphics pinceau2 = pinceau.create();
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
pinceau2.setColor(this.getBackground());
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
}
pinceau2.drawImage(this.image, 768, 1024, this);
}
}

Binary file not shown.

View File

@@ -0,0 +1,22 @@
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class MainImage{
public static void main(String[] args) {
try{
FileInputStream file = new FileInputStream("image.bin");
try {
JFrame fenetre = new JFrame();
fenetre.setSize(1024, 768);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.add(new Imag(1024, 768, "image.bin"));
fenetre.setVisible(true);
fenetre.pack();
file.close();
} catch(IOException e){}
}catch(FileNotFoundException e){}
}
}

Binary file not shown.