topical media & game development
#graphic-flex-image-effects-04-Flex-PixelDissolveTest.ax
#graphic-flex-image-effects-04-Flex-PixelDissolveTest.ax
[swf]
[flash]
flex
package {
import flash.display.BitmapData;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
[SWF(width=400, height=600, backgroundColor=0x000000)]
Creates a pointist painting effect using BitmapData's pixelDissolve()
to introduce white pixels into an image.
public class @ax-graphic-flex-image-effects-04-Flex-PixelDissolveTest extends graphic_flex_image_effects_04_Flex_AbstractImageLoader {
Constructor. Passes path of image to load to super class.
public function @ax-graphic-flex-image-effects-04-Flex-PixelDissolveTest() {
super("graphic-flex-image-effects-04-assets-fungus.jpg");
}
Called when image completes loading in super class.
This invokes pixelDissolve() on image to introduce random white pixels.
override protected function runPostImageLoad():void {
var bitmapData:BitmapData = _loadedBitmap.bitmapData;
// affect 1/3 of the pixels
var numPixels:uint = (bitmapData.width*bitmapData.height)/3;
bitmapData.pixelDissolve(
bitmapData,
bitmapData.rect,
new Point(),
0,
numPixels,
0xFFFFFFFA
);
// desaturate and blur the result
_loadedBitmap.filters = [getSaturationFilter(), new BlurFilter()];
addChild(_loadedBitmap);
}
Returns the ColorMatrixFilter needed to desaturate an image slightly.
returns: The ColorMatrixFilter needed to desaturate an image slightly.
private function getSaturationFilter():ColorMatrixFilter {
var r:Number = 0.3;
var g:Number = 0.59;
var b:Number = 0.11;
// the amount to desaturate
var amount:Number = 2.2;
var inverse:Number = 1-amount;
var matrix:Array=[
inverse*r+amount, inverse*g, inverse*b, 0, 0,
inverse*r, inverse*g+amount, inverse*b, 0, 0,
inverse*r, inverse*g, inverse*b+amount, 0, 0,
0, 0, 0, 1, 0
];
return new ColorMatrixFilter(matrix);
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.