| 12
 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
 
 |  
    BufferedImage img_in = null;
    BufferedImage img_out = null;
 
    File file_in = new File("C:\\Lenna.png");
    File file_out = new File("C:\\Lenna_out.png");
 
    try {
        img_in = ImageIO.read(file_in);
    } catch ( IOException e ) {
        System.err.println("interrupted waiting for load img!");
    }
 
    int width = img_in.getWidth();
    int height = img_in.getHeight();
 
    int[] pixels_in = new int[width * height];
    PixelGrabber pg_in = new PixelGrabber(img_in, 0, 0, width, height, pixels_in, 0, width);
    try {
	pg_in.grabPixels();
    } catch (InterruptedException e) {
	System.err.println("interrupted waiting for pixels!");
    }
 
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image img1 = tk.createImage(new MemoryImageSource(width, height, pixels_in, 0, width));
 
    Image image1 = new ImageIcon(img1).getImage();
    img_out = new BufferedImage(image1.getWidth(null),image1.getHeight(null),BufferedImage.TYPE_INT_RGB );
 
 
    int x = 0;
    int y = 0;
 
    //on copie l'image
    for (x=0; x<width; x++) {
        for (y=0; y<height; y++) {
 
            img_out.setRGB(x, y, img_in.getRGB(x, y));
 
        }
    }
 
    // sauvegarde dans l'image résultat
    try {
        ImageIO.write(img_out, "png", file_out);
    } catch (IOException e) {
        e.printStackTrace();
    } | 
Partager