1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Histogrammebilineaire extends JPanel {
BufferedImage monImage;
BufferedImage monImage2;
public Histogrammebilineaire() {
File input = new File("d:/capture2.PNG");
File input2 = new File("d:/Capture.PNG");
try {
monImage = ImageIO.read(input);
} catch (IOException e) {
e.printStackTrace();
}
try {
monImage2 = ImageIO.read(input2);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void Fenetre() {
JFrame fenetre = new JFrame();
fenetre.setSize(273, 295);
fenetre.setTitle("Histogramme Bilinéaire");
JPanel panneau = new Histogrammebilineaire();
panneau.setBackground(Color.WHITE);
fenetre.add(panneau);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLocationRelativeTo(null);
fenetre.setVisible(true);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int larg = getWidth();
int haut = getHeight();
int dim = 8; // dimension d'une case de la grille
//int largeurImage = Math.min(monImage.getWidth(), monImage2.getWidth());
//int hauteurImage = Math.min(monImage.getHeight(), monImage2.getHeight());
int largeurImage1=monImage.getWidth();
int hauteurImage1=monImage.getHeight();
int largeurImage2=monImage2.getWidth();
int hauteurImage2=monImage2.getHeight();
for (int i = 0; i < largeurImage1; i++) {
for (int j = 0; j < hauteurImage1; j++) {
int pixel = monImage.getRGB(i, j);
int gray = ((pixel >> 16) & 0xFF) >> 3;
for (i = 0; i < largeurImage2; i++) {
for (j = 0; j < hauteurImage2; j++) {
int pixel2 = monImage2.getRGB(i, j);
int gray2 = ((pixel2 >> 16) & 0xFF) >> 3;
//int valeur = (gray + gray2);
//g.setColor(new Color(valeur, valeur, valeur));
g.fillRect(gray2 * dim, gray * dim,dim, dim); // remplissage (fill)
}
}}}
g.setColor(Color.WHITE); // donner une couleur à la grille, sinon ça prend la dernière couleur de l'histo
for(int i = 0; i < larg; i +=dim) {
g.drawLine(i,0,i, haut); // Les lignes verticales de la grille
}
for(int i = 0; i < haut; i +=dim) {
g.drawLine(0,i,larg, i); // Les lignes horizontales de la grille
}
}
public static void main(String[] arg) {
Fenetre();
}
} |
Partager