package imageanalyser; import java.awt.*; import java.awt.image.*; import javax.imageio.*; import java.awt.event.*; import javax.swing.*; import java.io.*; /** *
Title: Traiteur d'image
*Description: En annalysant une image pixel par pixel, ce programme peut apporter divers traitements à des image
*Copyright: Copyright (c) 2004
*Company:
* @author Parchet Michaël * @version 1.0 */ public class ImageOriginale extends JFrame { private ImageViewer image; private File defaultDirectory; public ImageOriginale() { init(); } /** * Cette méthode initialise la fenêtre */ private void init() { this.charger(); if (image != null) { // Dimension dimScrean = new Dimension(getToolkit().getScreenSize()); //dimImages.width = dimScrean.width / 2; //dimImages.height = dimScrean.height / 2; // imgSource = getToolkit().getImage(source); this.setTitle("Image Originale"); this.setLocation((ImageViewer.dimScrean.width - this.getWidth()) / 2 ,(ImageViewer.dimScrean.height - this.getHeight()) / 2); this.addWindowListener(new QuitManager()); this.setVisible(true); } } void charger() { int returnVal; // File defautderectory = null; File imageFile = null; JFileChooser choser = new JFileChooser(); if (defaultDirectory == null) choser = new JFileChooser(); else choser = new JFileChooser(defaultDirectory); ImageFileFilter defaultFilter = new ImageFileFilter(); choser.setFileFilter(defaultFilter); choser.setFileFilter(new ExtentionFilter("jpg","photo jpeg")); choser.setFileFilter(new ExtentionFilter("gif","Image gif")); choser.setFileFilter(new ExtentionFilter("png","Image png")); choser.setFileFilter(new ExtentionFilter("bmp","Image bmp")); choser.setFileFilter(defaultFilter); // ne pas permettre de sélectionner tous les fichier choser.removeChoosableFileFilter(choser.getAcceptAllFileFilter()); // afficher la zone de dialogue ouvrir returnVal = choser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { imageFile = choser.getSelectedFile(); defaultDirectory = choser.getCurrentDirectory(); System.out.println(imageFile); // source = imageFile.getAbsolutePath(); image = new ImageViewer(imageFile); Selector select = new Selector(50,150,400,200); image.add(select); this.add(image); this.pack(); this.setContentPane(image); } this.addComponentListener(new ReseizeManager()); } class ReseizeManager extends ComponentAdapter { public void componentResized(ComponentEvent e) { System.out.println("resize"); image.setSize(image.CorrigerDimenssion(ImageOriginale.this.getSize())); ImageOriginale.this.setSize(image.getSize()); System.out.println("taille de l'image"+image.getSize()); System.out.println("taille de la fenêtre"+ImageOriginale.this.getSize()); } } } class EcouteurCharger implements ActionListener { ImageOriginale fenetre; public EcouteurCharger(ImageOriginale fenetre) { this.fenetre = fenetre; } public void actionPerformed(ActionEvent e) { if (fenetre == null) fenetre = new ImageOriginale(); fenetre.charger(); } }