As3 | How to export PNG using Adobe AIR

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(); 

Everything works fine - except for the transparent issue ...

If I could get the color of the Flash scene, then it will work - but, unfortunately, there is no such option.

Are there any options that I am missing?

+6
source share
1 answer

You need to create an instance of BitmapData with a transparent background. You do this through the transparent argument in the constructor and the fill color with the alpha component (ARGB in hexadecimal format):

 var pngSource:BitmapData = new BitmapData (stage.stageWidth, stage.stageHeight,true,0x00FFFFFF);//'transparent white' 
+6
source

Source: https://habr.com/ru/post/889377/


All Articles