package pic;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Color;
public class pro {
public static void main(String[] args) {
pro t=new pro();
}
pro(){
try {
File f = new File("b.jpg");
BufferedImage bi = ImageIO.read(f);
int w =bi.getWidth();
int h =bi.getHeight();
int x,y;
int[][] g1=new int[w][h];
for(x=0;x<w;x++){
for(y=0;y<h;y++){
int rgb = bi.getRGB(x,y);
rgb = 0-rgb;
int b = rgb%256;
int g = (rgb/256)%256;
int r = rgb/256/256;
g1[x][y] = (int)((0.299*r + 0.587*g + 0.114*b));
}}
BufferedImage off = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
Graphics offsc = off.getGraphics();
offsc.setColor(Color.red);
for(x=0;x<w;x++){
for(y=0;y<h;y++){
offsc.setColor(new Color(255-g1[x][y], 255-g1[x][y], 255-g1[x][y]));
offsc.fillRect(x,y,1,1);
}}
String file="e.jpg";
offsc.dispose();
ImageIO.write(off, "jpeg", new File(file));
} catch (Exception e) {}
}
}
最終更新:2016年01月06日 19:58