Transforming Colors : Bitmap « Graphics « Flash / Flex / ActionScript






Transforming Colors

 
package {

    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.ColorTransform;

    public class Main extends Sprite {

        private var _loader:Loader = new Loader();
        private var _current:int;

        public function Main () {
            _loader.load(new URLRequest("http://www.java2s.com/image.jpg"));
            addChild(_loader);
            _loader.addEventListener(MouseEvent.CLICK, clickHandler);
            _loader.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
        }

        private function mouseMoveHandler(event:MouseEvent):void {
            var value:Number = _loader.mouseX / _loader.width;
            var colorTransform:ColorTransform = _loader.transform.colorTransform;
            if(_current == 0) {
                colorTransform.redMultiplier = value;
            }
            else if(_current == 1) {
                colorTransform.greenMultiplier = value;
            }
            else if(_current == 2) {
                colorTransform.blueMultiplier = value;
            }
            else if(_current == 3) {
                colorTransform.alphaMultiplier = value;
            }
            _loader.transform.colorTransform = colorTransform;
        }

        private function clickHandler(event:MouseEvent):void {
            _current++;
            if(_current == 4) {
                _current = 0;
            }
        }
    }
}

        








Related examples in the same category

1.Copying Pixels: bitmap.copyPixels(sourceBmp, srcRect, destPoint);
2.Use perlinNoise
3.Apply filter to bitmap
4.Create bitmap and set pixel
5.Dissolving Between Two Bitmaps
6.Add Bitmap to Sprite
7.Embedding a bitmap at compile time
8.Examining a Bitmap
9.An image-based color picker
10.Display objects composited into a bitmap
11.Runtime Bitmap
12.Applying Flood Fills
13.Pixel Snapping
14.Image Smoothing
15.Copying Images
16.Applying Rectangular Fills
17.Adding a Bitmap Fill