Skip to content
Snippets Groups Projects
Select Git revision
  • 7715a07c99d460f3a820bff96c320f60d7e4e957
  • main default protected
  • variant
3 results

Board.java

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Main.java 1.78 KiB
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.io.IOException;
    
    
    public class Main 
    {
    
        public static void main(String[] args) {
        	MatrixGrayImage image = 
        			MatrixGrayImage.createImageFromPGMFile("luminy.pgm");   
        	
    	// Add code here;
        	Invert invert = new Invert();
            DecreaseGrayLevels decreaseGrayLevel = new DecreaseGrayLevels(5);
        	Pixelate pixelate = new Pixelate(10);
            
            invert.applyTo(image);
            pixelate.applyTo(image);
            decreaseGrayLevel.applyTo(image);
    
        	display(image);
    	
        }
    
        
        /** Methode pour visulaiser l'image. NE PAS MODIFIER !! **/   
        public static void display(MatrixGrayImage image) {
        	JFrame frame = new JFrame();
            int width = image.getWidth(); 
            int height = image.getHeight();
            frame.setSize(width, height);
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(new ImagePanel(width, height, image));
            frame.setVisible(true);
    
        }
        
        private static class ImagePanel extends JPanel {
            private BufferedImage image;
            public ImagePanel(int width, int height, MatrixGrayImage myimage) {
                this.image = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY); 
                
                for (int i = 0; i < image.getWidth(); i++) {
                    for (int j = 0; j < image.getHeight(); j++) {
                        image.setRGB(i, j, myimage.getPixelByteColor(i,j));
                    }
                }
                repaint();
            }
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
            }
        }
    
    }