java 图像特效之油画

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

油画也算是一种常见的艺术品了,谁说咱们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;
	}


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

效果是不是还不错~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值