Sunday, 15 December 2013

Eliminate background given two images, reduce reds to get transparency -> AS3

package  {
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.Rectangle;
    import flash.geom.Point;
   
    public class MergeBitmap extends Sprite {
         //Given 2 images (one normal the other the mask in alphachannel) merge 'em and to get an alphachannel image (an image without background), Useful if you want to eliminate bgr.

         public function merge (img:BitmapData, alphachannelMask:BitmapData) :Bitmap
        {
            var merged:BitmapData = new BitmapData(img.width, img.height, true, 0);
            var rect:Rectangle = new Rectangle(0, 0, img.width, img.height);
            merged.copyPixels(img, rect, new new Point());
            merged.copyChannel(alphachannelMask, new Rectangle(0, 0, img.width, img.height), new Point(), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
            return new Bitmap(merged);
        }
       
        public function FromRedToTransparent( original:BitmapData ):BitmapData {//Diminish reds in image eliminate blacks results transparency and a black shape
            var bmd:BitmapData = new BitmapData( original.width, original.height, true, 0x00000000 );
            bmd.copyChannel( original, bmd.rect, new Point(), BitmapDataChannel.RED,BitmapDataChannel.ALPHA );
            return bmd;
        }

    }
   
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.