I'm using copyPixels
to copy a parts of a larger Bitmap to smaller Bitmaps to use for individual MovieClips. However, around there is still some extra space white space and corners around the Bitmaps' edges left over. How do I set the color white in the Bitmap to be transparent so I won't see these unsightly edges?
Asked
Active
Viewed 5,230 times
1
2 Answers
5
You can use the BitmapData.threshold method. This code creates a BitmapData with a red square on a blue background, then uses the threshold method to make the red pixels transparent.
var inputBitmapData:BitmapData = new BitmapData(200, 200, true, 0xFF0000FF);
inputBitmapData.fillRect(new Rectangle(10, 10, 180, 180), 0xFFFF0000);
var outputBitmapData:BitmapData = new BitmapData(200, 200, true);
var destPoint:Point = new Point(0, 0);
var sourceRect:Rectangle = new Rectangle(0, 0, outputBitmapData.width, outputBitmapData.height);
var threshold:uint = 0xFFFF0000;
var color:uint = 0x00000000;
outputBitmapData.threshold(inputBitmapData, sourceRect, destPoint, "==", threshold, color, 0xFFFFFFFF, true);
var input:Bitmap = new Bitmap(inputBitmapData);
addChild(input);
var output:Bitmap = new Bitmap(outputBitmapData);
output.x = input.x + input.width + 10;
addChild(output);

Sean Fujiwara
- 4,506
- 22
- 34
-
This function looks super flexible. I'll try it out, and thanks for the example! – Mar 22 '11 at 00:36
0
you can use BitmapData.colorTransform()
or draw()
instead of copyPixels()
to adjust color there

www0z0k
- 4,444
- 3
- 27
- 32
-
Ah, I see. But how would I specify the color white, which is 0xFFFFFF to be rendered as transparent? Do I edit the alphaOffset or alphaMultiplier? – Mar 21 '11 at 20:20