import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
public class Java2DTest20
{
public static void main(String args[])
throws Exception
{
/* 画像をセピア調に変換する */
BufferedImage img = ImageIO.read(new File("sf.jpg"));
WritableRaster wr = img.getRaster();
int buf[] = new int[wr.getNumDataElements()];
for(int ly=0;ly<wr.getHeight();ly++){
for(int lx=0;lx<wr.getWidth();lx++){
wr.getPixel(lx, ly, buf);
int maxval = Math.max(Math.max(buf[0], buf[1]), buf[2]);
int minval = Math.min(Math.min(buf[0], buf[1]), buf[2]);
int val = (maxval+minval)/2;
buf[0] = val * 0xd0/0xff;
buf[1] = val * 0xa0/0xff;
buf[2] = val * 0x50/0xff;
wr.setPixel(lx, ly, buf);
}
}
ImageIO.write(img, "jpg", new File("sample744a.jpg"));
}
}
元画像(sf.jpg)
出力画像(sample744a.jpg)
No comments:
Post a Comment