DEV/DEV2.1/TP7/image.java

44 lines
942 B
Java
Raw Normal View History

2023-04-27 11:24:21 +02:00
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Image {
public static void main(String[] args) {
//ouverture du fichier
try
{
FileInputStream fos = new FileInputStream("image.bin");
}
catch(IOException e)
{
System.out.println("Erreur Ouverture du fichier");
}
try
{
BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
for(int x = 0;x<768;x++)
{
for(int y = 0;y<1024;y++)
{
int r = input.read();
int g = input.read();
int b = input.read();
int rgb = (r<<16)|(g<<8)|(b);
img setRGB(x,y,rgb);
}
}
}
catch( IOException e)
{
System.out.println("Erreur Lecture du fichier");
}
Frame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel image = new JLabel(new ImageIcon(img));
frame.add(image);
frame.pack();
frame.setVisible(true);
}
}