Send ByteArray to JavaScript

后端 未结 3 1458
夕颜
夕颜 2021-02-14 22:33

How to send a jpg image as ByteArray from as3 to javascript? And how to convert ByteArray to image in javascript?

3条回答
  •  走了就别回头了
    2021-02-14 23:25

    Take your DisplayObject (Sprite/MovieClip/whatever) and convert it to a BitmapData:

    myBitmapData.draw(mySprite);
    

    Convert that to a PNG using adobe's AS3CoreLib

    myByteArray = PNGEncoder.encode(myBitmapData);
    

    Convert that to Base64 using Flex's Base64Encoder:

    myBase64Encoder.encodeBytes(myByteArray);
    

    Then export actionscript variables to Javascript using ExternalInterface.

提交回复
热议问题