Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this code could help you:</p> <pre><code>import flash.utils.ByteArray; import flash.display.Loader; import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.Event; import mx.utils.Base64Decoder; //Transform String in a ByteArray. import mx.utils.Base64Encoder; //Transform ByteArray in a readable string. import mx.graphics.codec.PNGEncoder; //Encode a BitmapData in a PNG; var myBMD:BitmapData=new myBitmapData(0,0); //In this case I had a BitmapData in the library so I took it from there. var myBMDByteArray:ByteArray=(new PNGEncoder).encode(myBMD); //Create the ByteArray of myBMD usinf the PNGEncoder. var compStr:String=compress(myBMDByteArray); //Creates String trace(compStr); // The loader acts exactly as we were loading an external PNG except the fact that we write the ByteArray. var loader:Loader = new Loader(); loader.loadBytes(uncompress(compStr)); // In the loadBytes we write the Base64 String of the image. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); function loadComplete(e:Event):void { var bmp:BitmapData=new BitmapData(loader.width,loader.height,true,0x0); bmp.draw(loader); addChild(new Bitmap(bmp)); } // Compress a ByteArray into a Base64 String. function compress(bytes:ByteArray):String { var enc:Base64Encoder = new Base64Encoder(); enc.encodeBytes(bytes); return enc.drain().split("\n").join(""); } // Uncompress a Base64 String into a ByteArray. function uncompress(str:String):ByteArray { var dec:Base64Decoder = new Base64Decoder(); dec.decode(str); var newByteArr:ByteArray=dec.toByteArray(); return newByteArr; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload