import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.imageio.*;
public class Java2DTest17
{
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);
buf[0] = (byte)255 - buf[0];
buf[1] = (byte)255 - buf[1];
buf[2] = (byte)255 - buf[2];
wr.setPixel(lx, ly, buf);
}
}
ImageIO.write(img, "jpg", new File("sample541a.jpg"));
}
}
元画像(sf2.jpg)
出力画像(sample541a.jpg)
No comments:
Post a Comment