Laan's steps..

Feed Rss

水彩滤镜

11.11.2008, flash, flex, js, 快乐生活, by .

I had studied effect of BitmapData in actionscript3 yesterday. You check the article here.

But now, when I use it in my project. I findthat the Aquarelle effect working is very slow. So  I stop my job to re-think how to create the Aquarelle Effect.

And than, I find the DisplacementMapFilter class in as3. That is great! The Aquarelle Effect is just to replace pixel by an other pixl nearly. But, One more question:the effect do displacement random. Immediately,I think of the noise method of BitmapData. So, using DIsplacementMapFilter and BitampData’s noise method, the Aquarelle Effect should been work.

Minutes later, I had done that.

Following is the original code:

var bitmap:BitmapData;

for (var i:uint = 1; i < bitmap.width – 1; i++) {

for (var j:uint = 1; j < bitmap.height – 1; j++) {

if (Math.random() > factor) continue;

var ii:uint = i + (Math.random() > 0.5 ? 1 : -1);

var jj:uint = j + (Math.random() > 0.5 ? 1 : -1);

bitmap.setPixel(i, j, bitmap.getPixel(ii, jj));

}

}

And next block is the new code using DisplacementMapFilter–that work perfectly!

var no:BitmapData = new BitmapData(img_.width, img_.height);

no.noise(6, 0, 255, BitmapDataChannel.RED);

var chanel:uint = BitmapDataChannel.RED;

var filter:DisplacementMapFilter = new DisplacementMapFilter(no, new Point(0, 0), chanel, chanel, 2, 2);

//add the filter to the target

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>