diff --git a/images/joueur.png b/images/joueur.png new file mode 100644 index 0000000..45cc75d Binary files /dev/null and b/images/joueur.png differ diff --git a/images/zombie.png b/images/zombie.png new file mode 100644 index 0000000..8e8f46d Binary files /dev/null and b/images/zombie.png differ diff --git a/src/graphique/JPanelImage.java b/src/graphique/JPanelImage.java index 2b2dedb..ea1545a 100644 --- a/src/graphique/JPanelImage.java +++ b/src/graphique/JPanelImage.java @@ -10,6 +10,15 @@ import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JPanel; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + + +//import ij.ImagePlus; +//import ij.process.ImageProcessor; +//import java.io.File; +//import java.io.IOException; + public class JPanelImage extends JPanel { @@ -33,6 +42,45 @@ public class JPanelImage extends JPanel { chargerImage(); } + public static void redim(String[] args) throws IOException { + int newWidth = 300; // nouvelle largeur + int newHeight = 200; // nouvelle hauteur + File input = new File("/images/joueur.png"); // chemin de l'image d'origine + BufferedImage originalImage = ImageIO.read(input); // lecture de l'image d'origine + BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType()); // création d'une nouvelle image avec les dimensions souhaitées + Graphics2D g = resizedImage.createGraphics(); // création d'un objet Graphics2D pour dessiner sur la nouvelle image + g.drawImage(originalImage, 0, 0, newWidth, newHeight, null); // dessin de l'image d'origine sur la nouvelle image + g.dispose(); // libération des ressources du Graphics2D + String format = "png"; // format de l'image de sortie + File output = new File("/images/joueur-redim.png"); // chemin de l'image de sortie + ImageIO.write(resizedImage, format, output); // écriture de la nouvelle image dans un fichier + } + +// public static void main(String[] args) throws IOException { +// int newWidth = 300; // nouvelle largeur +// int newHeight = 200; // nouvelle hauteur +// File input = new File("image.jpg"); // chemin de l'image d'origine +// ImagePlus imp = new ImagePlus(input.getAbsolutePath()); // création d'un objet ImagePlus à partir de l'image d'origine +// ImageProcessor ip = imp.getProcessor(); // récupération de l'objet ImageProcessor pour manipuler l'image +// ip = ip.resize(newWidth, newHeight); // redimensionnement de l'image +// String format = "jpg"; // format de l'image de sortie +// File output = new File("image_redimensionnee.jpg"); // chemin de l'image de sortie +// ImageIO.write(imp.getBufferedImage(), format, output); // écriture de la nouvelle image dans un fichier +// } +// +// //redimensionner image +// int newWidth = 300; // nouvelle largeur +// int newHeight = 200; // nouvelle hauteur +// File input = new File("joueur.png"); // chemin de l'image d'origine +// BufferedImage originalImage = ImageIO.read(input); // lecture de l'image d'origine +// BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType()); // création d'une nouvelle image avec les dimensions souhaitées +// Graphics2D g = resizedImage.createGraphics(); // création d'un objet Graphics2D pour dessiner sur la nouvelle image +// g.drawImage(originalImage, 0, 0, newWidth, newHeight, null); // dessin de l'image d'origine sur la nouvelle image +// g.dispose(); // libération des ressources du Graphics2D +// String format = "png"; // format de l'image de sortie +// File output = new File("image_redimensionnee.png"); // chemin de l'image de sortie +// ImageIO.write(resizedImage, format, output); // écriture de la nouvelle image dans un fichier +// private void chargerImage(){ if(sNomImage!=null) { String sNomFile=".\\images\\"+sNomImage; diff --git a/src/graphique/MaJFrame.java b/src/graphique/MaJFrame.java index 1c0f0cf..74a67c1 100644 --- a/src/graphique/MaJFrame.java +++ b/src/graphique/MaJFrame.java @@ -31,6 +31,7 @@ import java.awt.FlowLayout; import javax.swing.JTextPane; import javax.swing.SwingConstants; import java.awt.Font; +import java.awt.Graphics; import java.awt.Window.Type; import java.awt.GridBagConstraints; import java.awt.Insets; @@ -41,6 +42,16 @@ import java.awt.CardLayout; import javax.swing.JLayeredPane; import javax.swing.border.CompoundBorder; +import java.awt.image.BufferedImage; +import java.io.File; +import java.awt.Graphics2D; + +//import java.awt.Graphics2D; +//import java.awt.image.BufferedImage; +//import java.io.File; +//import java.io.IOException; +//import javax.imageio.ImageIO; + public class MaJFrame extends JFrame { @@ -65,8 +76,8 @@ public class MaJFrame extends JFrame { private JProgressBar progressBarAttaque; private JPanelImage panelMap; private JPanelDessin panelGrille; - private ImageIcon joueurIcon; private JLabel lblJoueur; + private JLabel lblZombie; private JLabel lblNbZombiesTues; private JLabel lblNbZombies; // private Simulateur sim; @@ -136,7 +147,7 @@ public class MaJFrame extends JFrame { panelEnsemble.setLayout(gbl_panelEnsemble); //création panel Map - panelMap = new JPanelImage("map1.png"); + panelMap = new JPanelImage();//"map1.png" GridBagConstraints gbc_panelMap = new GridBagConstraints(); gbc_panelMap.insets = new Insets(0, 0, 18, 5); gbc_panelMap.fill = GridBagConstraints.BOTH; @@ -158,11 +169,38 @@ public class MaJFrame extends JFrame { gbl_panelGrille.rowWeights = new double[]{0.0}; panelGrille.setLayout(gbl_panelGrille); +// //redimensionner image +// int newWidth = 300; // nouvelle largeur +// int newHeight = 200; // nouvelle hauteur +// File input = new File("joueur.png"); // chemin de l'image d'origine +// BufferedImage originalImage = ImageIO.read(input); // lecture de l'image d'origine +// BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType()); // création d'une nouvelle image avec les dimensions souhaitées +// Graphics2D g = resizedImage.createGraphics(); // création d'un objet Graphics2D pour dessiner sur la nouvelle image +// g.drawImage(originalImage, 0, 0, newWidth, newHeight, null); // dessin de l'image d'origine sur la nouvelle image +// g.dispose(); // libération des ressources du Graphics2D +// String format = "png"; // format de l'image de sortie +// File output = new File("image_redimensionnee.png"); // chemin de l'image de sortie +// ImageIO.write(resizedImage, format, output); // écriture de la nouvelle image dans un fichier + //ajout joueur lblJoueur = new JLabel(); - lblJoueur.setForeground(new Color(255, 128, 0)); - lblJoueur.setIcon(new ImageIcon(MaJFrame.class.getResource("/images/joueur.png"))); + int newWidth = 100; + int newHeight = 100; +// File fJoueur = new File("/images/joueur.png"); +// System.out.println("fJo = "+fJoueur); + try { + Image originalJoueur =Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/joueur.png")); + BufferedImage reJoueur = new BufferedImage(originalJoueur.getWidth(null), originalJoueur.getHeight(null),BufferedImage.TYPE_INT_ARGB); + Image redimJoueur= reJoueur.getScaledInstance(newWidth, newHeight,Image.SCALE_DEFAULT); + Graphics g = redimJoueur.getGraphics(); + g.drawImage(originalJoueur, 0, 0, null); + g.dispose(); + lblJoueur.setIcon(new ImageIcon(redimJoueur)); + } + catch(Exception e) { + } +// lblJoueur.setIcon(new ImageIcon(MaJFrame.class.getResource("/images/joueur.png"))); GridBagConstraints gbc_joueur = new GridBagConstraints(); gbc_joueur.fill = GridBagConstraints.CENTER; gbc_joueur.gridx = 2; @@ -171,6 +209,20 @@ public class MaJFrame extends JFrame { gbc_joueur.gridheight = 1; // Occupy 1 row gbc_joueur.anchor = GridBagConstraints.CENTER; panelGrille.add(lblJoueur, gbc_joueur); + lblJoueur.setVisible(true); + + + //ajout zombie + lblZombie = new JLabel(); + lblZombie.setIcon(new ImageIcon(MaJFrame.class.getResource("/images/zombie.png"))); + GridBagConstraints gbc_zombie = new GridBagConstraints(); + gbc_zombie.fill = GridBagConstraints.CENTER; + gbc_zombie.gridx = 5; + gbc_zombie.gridy = 7; + gbc_zombie.gridwidth = 1; // Occupy 1 column + gbc_zombie.gridheight = 1; // Occupy 1 row + gbc_zombie.anchor = GridBagConstraints.CENTER; + panelGrille.add(lblZombie, gbc_zombie);