光晕,听起来很美。实现起来也很简单,本文实现了一个随机光晕。属于比较简单的。那种美伦美幻的,比较复杂,先从简单的开始~
所谓光晕,就是中间特别亮,然后向四周递减,在最边缘达到和正常一样~,我们只要在一个随机圆的范围内,给图像增加亮度即可。
说完原理,来看代码:
public Image filter() {
int[] d = new int[this.img.w*this.img.h]; //must be writed as this.not int[] d = this.img.data;
int cenX = (int)(Math.random()*this.img.w);
int cenY = (int)(Math.random()*this.img.h);
int therash = this.img.w/6;
for (int y = 0; y < this.img.h ; y++) {
for (int x = 0; x < this.img.w; x++) {
d[x + y * this.img.w] = getRGB(cenX,cenY,x,y,therash);
}
}
this.img.data = d;
return this