Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset
Comments Off

Java: Créer une image multiniveau de gris

 set, swing, awt, JPanel, JFrame
Download

         


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ImageMultiniveau extends JPanel 
{

  public void paint(Graphics g) {
    Image image = new ImageIcon("c:/image.gif").getImage();
    BufferedImage bufferedImage = new BufferedImage(image.getHeight(this), image.getWidth(this), BufferedImage.TYPE_BYTE_GRAY);

    Graphics gi = bufferedImage.getGraphics();
    gi.drawImage(image, 0, 0, null);
    gi.dispose();
    
    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(bufferedImage, null, 0, 0);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Image Grise Multiniveau");
    frame.add(new ImageMultiniveau());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400,400);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}