1 2 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
| public class TestApplet extends Applet {
private static final long serialVersionUID = 1748168598860228572L;
private BufferedImage bufferedImage = null;
public void init() {
setBackground(Color.black);
}
public void paint(Graphics g) {
// on créé l'image
this.bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics2D = this.bufferedImage.createGraphics();
// on dessine ici le rectangle vert
graphics2D.setColor(Color.green);
graphics2D.fillRect(50, 50, 100, 100);
// on dessine le tout
g.drawImage(this.bufferedImage, 0, 0, 200, 200, this);
int color = this.bufferedImage.getRGB(15, 15);
System.out.println(new Color(color));
color = this.bufferedImage.getRGB(55, 55);
System.out.println(new Color(color));
color = this.bufferedImage.getRGB(145, 145);
System.out.println(new Color(color));
color = this.bufferedImage.getRGB(185, 185);
System.out.println(new Color(color));
}
} |
Partager