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