27 Avril
This commit is contained in:
BIN
DEV2.1/TP9:FluxOctets/Imag.class
Normal file
BIN
DEV2.1/TP9:FluxOctets/Imag.class
Normal file
Binary file not shown.
41
DEV2.1/TP9:FluxOctets/Imag.java
Normal file
41
DEV2.1/TP9:FluxOctets/Imag.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP9:FluxOctets/MainImage.class
Normal file
BIN
DEV2.1/TP9:FluxOctets/MainImage.class
Normal file
Binary file not shown.
22
DEV2.1/TP9:FluxOctets/MainImage.java
Normal file
22
DEV2.1/TP9:FluxOctets/MainImage.java
Normal 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){}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP9:FluxOctets/image.bin
Normal file
BIN
DEV2.1/TP9:FluxOctets/image.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user