画像エフェクタ
import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.image.*; public class WhiteOut extends Applet { Image image; Button load = new Button(); Button button2 = new Button(); public void init() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } //コンポーネントの初期化 private void jbInit() throws Exception { load.setLabel("load"); load.setBounds(new Rectangle(15, 170, 70, 25)); load.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { load_actionPerformed(e); } }); this.setLayout(null); button2.setLabel("white"); button2.setBounds(new Rectangle(100, 170, 80, 25)); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); this.add(load, null); this.add(button2, null); } public void paint(Graphics g) { int iwidth=0,iheight=0; if (image != null) { iwidth = image.getWidth(this); iheight = image.getHeight(this); //System.out.println("size="+iwidth+" "+iheight); g.drawImage(image, 0, 0, iwidth , iheight , this); } } void load_actionPerformed(ActionEvent e) { //ファイルを読みpixels[]に記録する image = getImage(getDocumentBase(), "ccad.gif"); //System.out.println("load="+image.getWidth(this)+" "+image.getHeight(this)); repaint(); } void button2_actionPerformed(ActionEvent e) { int iwidth = image.getWidth(this); int iheight = image.getHeight(this); //画素の配列 int pixels[] = new int[iwidth * iheight]; //ファイルを読みpixels[]に記録する PixelGrabber pg = new PixelGrabber(image, 0, 0, iwidth, iheight, pixels, 0, iwidth); try { pg.grabPixels(); } catch (InterruptedException ev) { } //色別に処理をする int x,y,red,green,blue; for (y = 0; y < iheight ; y++) { for (x = 0; x < iwidth ; x++) { red = (pixels[y * iwidth + x] & 0xFF) + 10; red = normal(red); green = ((pixels[y * iwidth + x] & 0xFF00) >> 8) + 10; green = normal(green); blue = ((pixels[y * iwidth + x] & 0xFF0000) >> 16) + 10; blue = normal(blue); pixels[y * iwidth + x] = (0xff000000 | blue << 16 | green << 8 | red); } } //表示用imageにする image =createImage(new MemoryImageSource(iwidth, iheight, pixels, 0, iwidth)); repaint(); } int normal(int col) { if (col < 0) return 0; if (col > 255) return 255; return col; } }