TP13
This commit is contained in:
BIN
APL2.1/TP13/Image/ImagePanel.class
Normal file
BIN
APL2.1/TP13/Image/ImagePanel.class
Normal file
Binary file not shown.
23
APL2.1/TP13/Image/ImagePanel.java
Normal file
23
APL2.1/TP13/Image/ImagePanel.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
|
||||
public class ImagePanel extends JPanel {
|
||||
private Image img;
|
||||
|
||||
public ImagePanel(Image img) {
|
||||
super();
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics newG = g.create();
|
||||
if (this.isOpaque()) {
|
||||
newG.setColor(this.getBackground());
|
||||
newG.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
newG.drawImage(img, 0, 0, img.getWidth(this), img.getHeight(this), this);
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP13/Image/ImageTest.class
Normal file
BIN
APL2.1/TP13/Image/ImageTest.class
Normal file
Binary file not shown.
48
APL2.1/TP13/Image/ImageTest.java
Normal file
48
APL2.1/TP13/Image/ImageTest.java
Normal file
@@ -0,0 +1,48 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageTest {
|
||||
static int width = 100;
|
||||
static int height = 100;
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage img = new BufferedImage(ImageTest.width, ImageTest.height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
try (FileInputStream f = new FileInputStream("../Coloriage/funny.bin")) {
|
||||
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
int r = f.read();
|
||||
int g = f.read();
|
||||
int b = f.read();
|
||||
|
||||
int rgb = r;
|
||||
rgb <<= 8;
|
||||
rgb |= g;
|
||||
rgb <<= 8;
|
||||
rgb |= b;
|
||||
|
||||
img.setRGB(i % width, i / width, rgb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
f.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
|
||||
JFrame f = new JFrame("Image");
|
||||
f.setSize(width + 50, height + 50);
|
||||
f.setLocation(100, 100);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.add(new ImagePanel(img));
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP13/Image/funny.bin
Normal file
BIN
APL2.1/TP13/Image/funny.bin
Normal file
Binary file not shown.
BIN
APL2.1/TP13/Image/image.bin
Normal file
BIN
APL2.1/TP13/Image/image.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user