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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Robot;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
/**
* Classe Ex1
*/
public class Ex1 extends JFrame{
private ImageIcon image=null;
private int couleurs[][];
public Ex1(ImageIcon image){
super("");
this.image=image;
setResizable(false);
setUndecorated(true);
int width=image.getIconWidth();
int height=image.getIconHeight();
setSize(width,height);
setLocation(300,300);
couleurs=new int[width][height];
try {
Robot robot = new Robot();
for(int x=0;x<width;x++){
couleurs[x]=new int[height];
for(int y=0;y<height;y++){
couleurs[x][y]=robot.getPixelColor(300+x,300+y).getRGB();
}
}
} catch (AWTException e1) {
e1.printStackTrace();
}
setBackground(Color.WHITE);
setVisible(true);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
dispose();
}
/* (non-Javadoc)
* @see java.awt.Component#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
Graphics2D gc=(Graphics2D)g;
Image imageBuffer=createImage(couleurs.length,couleurs[0].length);
Graphics buffer=imageBuffer.getGraphics();
for(int x=0;x<couleurs.length;x++){
for(int y=0;y<couleurs[x].length;y++){
buffer.setColor(new Color(couleurs[x][y]));
buffer.drawLine(x,y,x,y);
}
}
buffer.drawImage(image.getImage(),0,0,this);
gc.drawImage(imageBuffer,0,0,this);
}
public static void main(String args[]) {
new Ex1(new ImageIcon("toto.gif"));
}
} |
Partager