import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
class game1007 extends Frame implements ActionListener {
PixelGrabber pg;
Button button1,button2;
Image img,img2;
int w=500;
int h=500;
int button1push = 0;//画像読み込み[[ボタン]]
int button2push = 0;//処理開始ボタン
int pixels[]=[[new]] int[w*h];//ピクセルデータ(入力)配列
int pixels2[]=new int[w*h];//色変更したピクセル配列
game1007() {
setLayout(new FlowLayout(FlowLayout.LEFT));
img = createImage(w,h);//画像読み込み用 Image を生成
button1 = new Button("画像読込");
add(button1);
button1.addActionListener(this);
button2 = new Button("変色コピー");
add(button2);
button2.addActionListener(this);
}
public void paint(Graphics g) {
if(button1push>50)g.drawImage(img,20,[[100]],this);
if(button2push>50)g.drawImage(img2,100,100,this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1){
button1push=100;
button2push=0;
img = Toolkit.getDefaultToolkit().getImage("harada.jpg");
pg = new PixelGrabber(img,0,0,w,h,pixels,0,w);
try{
pg.grabPixels();
}catch(InterruptedException ie){}
repaint();
}
if(e.getSource() == button2){
button2push=100;
button1push=0;
for(int i=0;i<w*h;i++){
int p = pixels[i];
int red = 0xff & (p>>16);
int green = 0xff & (p>>8);
int blue = 0xff & p;
pixels2[i] = (0xff000000 | red << 8 | green << 16 | blue);
}
img2 = createImage(new MemoryImageSource(w, h, pixels2, 0, w));
repaint();
}
}
public static void main(String[] args) {
game1007 f = new game1007();
f.setSize(500,500);
f.addWindowListener(new WindowAdapter(){public void
windowClosing(WindowEvent e){System.exit(0);}});
f.setVisible(true);
}
}
最終更新:2011年03月06日 01:36