Merge 2 transparent BitmapDatas

Sunday, September 2nd, 2007

Maybe it’s just me, but I don’t know how to merge 2 transparent BitmapDatas. I know solution with draw() function, but I think, it should be possible with merge as well

Here is code:

import flash.display.*;
import flash.geom.*;

var bd1:BitmapData = new BitmapData(100,100,true,0×00ff0000);
var bd2:BitmapData = new BitmapData(100,100,true,0×00ff0000);

bd1.fillRect(new Rectangle(30,30,30,30),0xffff0000)
bd2.fillRect(new Rectangle(60,60,30,30),0xff00ff00)

//this is not working
//bd1.merge(bd2, new Rectangle(0,0,100,100),new Point(0,0),0×00,0×00,0×00,0xff);

var b2:Bitmap = new Bitmap(bd2);
//this is working
bd1.draw(b2);

var b1:Bitmap = new Bitmap(bd1);

this.addChild(b1);

I think solution is correctly set up multipliers, I’ve tried few combinations, but I didn’t find combination to merge 2 transparent BitmapDatas.

AddThis Feed Button

This is some text prior to the author information. You can change this text from the admin section of WP-Gravatar  I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets. Read more from this author


tagged under:

ABOUT THIS AUTHOR

I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets.

Get a Trackback link

1 Comments


  1. Mario Klingemann
    Visit Site
    September 3rd, 2007

    The problem with merge is that you can just get a mix between the two maps but not their sum. When you mix both maps 50/50 you could boost the channels afterwards by 200% with a colorTransform:

    bd1.merge(bd2, bd1.rect,new Point(0,0),0×80,0×80,0×80,0×80);
    bd1.colorTransform( bd1.rect,new ColorTransform(2,2,2,2));

    But I’m not sure if this will always give the same results like the draw() method.

Live Preview

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This site is using OpenAvatar based on
Images is enhanced with WordPress Lightbox JS by Zeo
Clicky Web Analytics