package { import aether.effects.adjustments.LevelsEffect; import aether.effects.common.CompositeEffect; import aether.effects.filters.BlurEffect; import aether.effects.filters.ColorMatrixEffect; import aether.effects.texture.NoiseEffect; import aether.effects.transformations.GridEffect; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Sprite; import flash.events.Event; import flash.geom.Matrix; [SWF(width=400, height=450, backgroundColor=0x666666)] /** * Demonstrates how frames from a loaded video can be drawn into bitmap data * so that visual effects may be applied. */ public class graphic_flex_image_effects_10_Flex_VideoFilters extends Sprite { public var _video:graphic_flex_image_effects_10_Flex_VideoLoader; public var _filteredScreen:Bitmap; /** * Constructor. Instantiates VideoLoader to load video, creates a bitmap/bitmap data * to display the video's frames and sets up a listener to know when the video frame changes. */ public function graphic_flex_image_effects_10_Flex_VideoFilters() { _video = new graphic_flex_image_effects_10_Flex_VideoLoader(400, 225, "graphic-flex-image-effects-10-assets-road.flv"); _video.addEventListener(Event.RENDER, onVideoRender); addChild(_video); _filteredScreen = new Bitmap(); _filteredScreen.y = _video.height; addChild(_filteredScreen); } /** * Handler for when the video frame updates. This draws the current video frame into the * bitmap data and applies an image effect. * * @param event Event dispatched by VideoLoader. */ private function onVideoRender(event:Event):void { var bitmapData:BitmapData = new BitmapData(_video.width, _video.height); // draws video frame into bitmap data, making sure it is at proper scale var matrix:Matrix = new Matrix(); matrix.scale(_video.scaleX, _video.scaleY); bitmapData.draw(_video, matrix); // comment/uncomment these lines to see different effects applied //new BlurEffect(5, 5, 1, BlendMode.SCREEN).apply(bitmapData); //new GridEffect(3, 3).apply(bitmapData); /* new CompositeEffect( [ new LevelsEffect(50, 127, 200), new ColorMatrixEffect(ColorMatrixEffect.SEPIA), new NoiseEffect(0.2, BlendMode.MULTIPLY, 0.3) ] ).apply(bitmapData); */ //new DissolveEffect().apply(bitmapData); new graphic_flex_image_effects_10_Flex_PointillismEffect().apply(bitmapData); _filteredScreen.bitmapData = bitmapData; } } }