时间:2021-03-16 10:20:34 | 栏目:JAVA代码 | 点击:次
首先使用PImage来实例化对象,再通过loadImage赋值,两层for循环遍历图片上的像素点,每隔5个像素点,画一个直径为3的圆。颜色通过pic.get(x,y)获取。
最后通过save函数来保存图片。
PImage pic;
int spacing=5;
void setup(){
pic=loadImage("steve.jpeg");
size(706, 644);
}
void draw(){
for (int x=spacing; x<width; x+=spacing) {
for (int y=spacing; y<height; y+=spacing) {
color c=pic.get(x, y);
fill(c);
noStroke();
ellipse(x, y, spacing*0.6, spacing*0.6);
}
}
save("image_2.jpg");
}

