as3 | How to export PNG using Adobe AIR
Asked Answered
U

1

6

I am trying to export transparent PNG files using this class: com.adobe.images.PNGEncoder;

var pngSource:BitmapData = new BitmapData (stage.stageWidth, stage.stageHeight);
pngSource.draw(stage);
var ba:ByteArray = PNGEncoder.encode(pngSource);
var file:File = File.desktopDirectory.resolvePath("test.png");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(ba);
fileStream.close();

All works fine - except the transparent issue...

If I could get Flash's stage color be transparent then it will work - but unfortunatly - there is no such option.

Are there any options I am missing?

Unbending answered 30/5, 2011 at 12:27 Comment(1)
Also recommend you to use better encoding library: blooddy.by/en/cryptoInaccurate
U
7

You need to make a BitmapData instance with a transparent background. You do that through the transparent argument in the constructor and a fill color with an alpha component(ARGB in hex):

var pngSource:BitmapData = new BitmapData (stage.stageWidth, stage.stageHeight,true,0x00FFFFFF);//'transparent white'
Undress answered 30/5, 2011 at 12:30 Comment(1)
You can set the color parameter to 0. The color will be transparent black, thenReeducate

© 2022 - 2024 — McMap. All rights reserved.