Convert MovieClip to ByteArray

I need to convert MovieClip to ByteArray and send it to php using the POST method. The person handling php says that only ByteArray needs to be sent, and conversion to JPG and PNG can be done from the PHP side. When I built the option to save to the local computer, the following steps were used.

  • Convert to Bitmapdata li>
  • Using JPGEncoder and PNGEncoder in bitmaps
  • Then, resorting to the byte variable of the array.

So, in this case, different byte arrays were used to save in the case of JPG and PNG, and it worked.

I found code to convert movieclip to bytearray in Stackoverflow itself

AS3: export MovieClip or Canvas to swf

var buffer:ByteArray = new ByteArray(); buffer.writeObject(MOVIE_CLIP_HERE); buffer.position = 0; buffer.writeBytes(...); 

What should be the parameter of the writeBytes function of the buffer object. Suppose the movie clip name is canvas_mc.

I already figured out the php part. Thank you in advance.

+4
source share
1 answer

You do not use ByteArray.writeObject() and parse MovieClip ..

You need to use bitmapData.getPixels() , which returns a ByteArray representing the pixels of your bitmap.

Here is an example:

 const WIDTH:uint = 100; const HEIGHT:uint = 100; var rect:Rectangle = new Rectangle(0,0,WIDTH,HEIGHT); // create BitmapData var bmd:BitmapData = new BitmapData(WIDTH,HEIGHT,true,0); bmd.draw(YOUR_MOVIE_CLIP); // your byte array var ba:ByteArray = bmd.getPixels(rect); trace(ba.length); 

Basically you want to use BitmapData.draw() to get MovieClip graphics and save them as ByteArray.

+5
source

All Articles