import java.awt.image.*;
import javax.imageio.*;
img = ImageIO.read(new File("sf.jpg"))
WritableRaster wr = img.getRaster()
buf = new int[wr.getNumDataElements()];
for(ly in (0..wr.height-1).step(2)){
for(lx in 0..wr.width-1){
wr.getPixel(lx, ly, buf)
buf[0] = buf[0]/2;
buf[1] = buf[1]/2;
buf[2] = buf[2]/2;
wr.setPixel(lx, ly, buf)
}
}
ImageIO.write(img, "png", new File("sample953a.png"));
元画像(sf.jpg)
出力画像(sample953a.png)
動作環境
Groovy1.6.0, JDK1.6 Update12
関連項目
Java2Dで画像をビデオ風にする
No comments:
Post a Comment