油画也算是一种常见的艺术品了,谁说咱们IT男不懂艺术~我们还能创造艺术,不多说,先说原理。
油画的算法很简单,对某一像素,用它附近随机一个像素来代替。没错就这么简单。
上代码:
public Image filter() {
if(this.img.gray)
return this.img; // Grayscale images can not be processed
int[] d = new int[this.img.w*this.img.h]; //must be writed as this.not int[] d = this.img.data;
for (int y = 4; y < this.img.h -4; y++) {
for (int x = 4; x < this.img.w -4; x++) {
int range = (int)(Math.random()*4)+1;
int sub = (range +1)/2;
int a = (int)(Math.random()*range)+1;
int b = (int)(Math.random()*range)+1;
d[x + y * this.img.w] = this.img.data[x+a-sub + (y+b-sub) * this.img.w];
}
}
this.img.data = d;
return this.img;
}
原图大家都很熟悉了,就不附上,上运行结果:
效果是不是还不错~