/ Published in: ActionScript 3
Expand |
Embed | Plain Text
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BitmapDataChannel; import flash.display.BlendMode; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.geom.ColorTransform; import flash.geom.Matrix; import flash.geom.Point; import flash.geom.Rectangle; public class Work extends Sprite { [Embed(source="image.jpg")] private var Image1:Class; [Embed(source="alpha.jpg")] private var Image2:Class; private var tx:Number = 10; private var ty:Number = 10; public function Work() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP; test1(); test2(); test3(); } private function test1():void { var source:BitmapData = (new Image1() as Bitmap).bitmapData; var offset:Matrix = new Matrix(); var bmd:BitmapData = new BitmapData(source.width-tx,source.height-ty,source.transparent,0xFF0000); bmd.copyChannel(source,new Rectangle(tx,ty,source.width,source.height),new Point(0,0), BitmapDataChannel.RED,BitmapDataChannel.RED); bmd.draw(source,offset, new ColorTransform(0),BlendMode.DIFFERENCE ); addChild( new Bitmap(bmd) ); } private function test2():void { var source:BitmapData = (new Image1() as Bitmap).bitmapData; var offset:Matrix = new Matrix(); offset.translate(tx,ty); var bmd:BitmapData = source.clone(); bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED); bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED); bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA); bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED); addChild( new Bitmap(bmd) ).y = 200; } private function test3():void { var source:BitmapData = (new Image2() as Bitmap).bitmapData; var offset:Matrix = new Matrix(); offset.translate(tx,ty); var bmd:BitmapData = source.clone(); bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED); bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED); bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA); bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED); addChild( new Bitmap(bmd) ).y = 400; } } }
You need to login to post a comment.
