62,630
社区成员
发帖
与我相关
我的任务
分享
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Demo {
public static void main(String[] args) {
int w=400;
BufferedImage im=new BufferedImage(w, w, BufferedImage.TYPE_INT_ARGB);
for(int i=0;i<w;i++){
for(int j=0;j<w;j++){
int r=(int)(i*i+2*i*j+j*j)%256;
int g=(int)(i*i+1.8*i*j+j*j)%256;
int b=(int)(i*i+2.2*i*j+j*j)%256;
int rgb=(r<<16)+(g<<8)+(b)+(0xff000000);
//System.out.println(Integer.toHexString(rgb));
im.setRGB(i, j, rgb);
}
}
File f=new File("D:/test.png");
try {
ImageIO.write(im, "png",f);
im.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}