简体   繁体   中英

Actionscript 3 - draw() with transparency on a Bitmap

I want to apply transparency to a non-transparent logo then add it to an image. So I change the alpha of the logo, then I draw() the logo on the image. But it doesn't work, the transparency isn't applied as expected.

Note: I will later save the resulting bitmapData to a file, so an addChild() won't be enough to solve this.

var image:Bitmap;
var logo:Bitmap;
//...
logo.alpha = 0.3;
image.bitmapData.draw(logo);

try this:

var adjustAlpha:ColorTransform = new ColorTransform();
adjustAlpha.alphaMultiplier = 0.3
var logoArea:Rectangle = new Rectangle(0, 0, logo.width, logo.height);
logo.bitmapData.colorTransform(logoArea, adjustAlpha);
image.bitmapData.draw(logo);

When you modify the alpha value of a bitmap you aren't modifying it's actual bitmapdata, so that when you draw it you are still copying the unmodified data found in bitmapData.

The code above uses the colorTransform property to adjust every pixel in bitmapData, you can target specific areas by changing the size of the rectangle.

(You will need to import the ColorTransform class also).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM