java 图像特效之油画

来源:互联网 发布:java获取客户端浏览器 编辑:程序博客网 时间:2024/04/26 10:44

阅读本系列,请先看前言!谢谢   

油画也算是一种常见的艺术品了,谁说咱们IT男不懂艺术~我们还能创造艺术,不多说,先说原理。

油画的算法很简单,对某一像素,用它附近随机一个像素来代替。没错就这么简单。

上代码:

public Image filter() {if(this.img.gray)return this.img;  // Grayscale images can not be processedint[] 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;}


原图大家都很熟悉了,就不附上,上运行结果:

效果是不是还不错~

0 0