/** * This example demonstrates inverting an alpha channel on an image. * Since Flash premultiplies the alpha, we need to keep two separate images: one with the color data, and * one with the alpha data. It demonstrates splitting the alpha from an image, inverting and proves * premultiplying the alpha destroys color information. * * @author J.C. Wichman / Objectpainters.com */ import flash.geom.Rectangle; import flash.geom.Point; import flash.display.BitmapData; import flash.filters.ColorMatrixFilter; //set up some default params for the images var width:Number = 100; var height:Number = 100; var fillColor:Number = 0x000000; /** * Simple function that checks how many bitmaps have already been shown on stage and * bases the location for the next one on that information. Never use code like this * out of context, since its bad programming practice:). */ function showBitmap (pBitmap:BitmapData, title:String) { var imageCount:Number = this.getNextHighestDepth(); var row:Number = Math.floor (imageCount/3); var columns:Number = imageCount%3; var newClip:MovieClip = this.createEmptyMovieClip("image"+imageCount, imageCount); newClip.attachBitmap(pBitmap, 0); newClip.createTextField("title", 1, 0, 110, 10,10); var textClip:TextField = newClip["title"]; textClip.autoSize = true; textClip.text = "Image "+imageCount+":\n"+title; var tf:TextFormat = new TextFormat(); tf.font = "Arial"; tf.align ="center"; textClip.setTextFormat(tf); newClip._x = (columns * 150)+10; newClip._y = (row * 170)+10; } //setting up demo rgb image, this is an image without alpha. //Since flash uses premultiplied alpha, adding an alpha channel will ruin the image for //further use when we want to invert the alpha channel, so we keep colours separate from alpha //(omg pink shirts!) var colorImage:BitmapData = new BitmapData(width, height, false, fillColor); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { //fiddle with the pixel data to show a dark gradient colorImage.setPixel( x,y, x<<16|y<<8|x+y); } } showBitmap (colorImage, "Colour w/o alpha"); //now we create a demo alpha bitmap. All color info is non existent, only //alpha data is set. When x