views:

18

answers:

1

I have a code like this:

var bitmapData:BitmapData = new BitmapData(width, height);
bitmapData.draw(this);
var ba:ByteArray = (new PNGEncoder()).encodeByteArray(bitmapData.getPixels(clipRect),width,height,true);

I want to make the white color in the generated PNG transparent. What is the best way to do so?

+1  A: 

You were close :)

You need to tell the bitmapData to be transparent, and then fill it with all transparent pixels.

var bitmapData:BitmapData = new BitmapData(width, height, true, 0);

(the 0 is shorthand for 0x00000000 which is a 32 bit ARGB color expressed as a uint)

Jonathan Dumaine