I have 开发者_运维问答to convert a MovieClip to ByteArray and send it to php using the POST method. The person handling php says that only ByteArray needs to be send and conversion to JPG and PNG can be done from PHP side. When I built the option for saving on the local machine the following steps were used.
- Converting to Bitmapdata
- Using JPGEncoder and PNGEncoder on the Bitmapdata
- Then assiging to byte array variable.
So in this case different byte arrays were used for saving in case of JPG and PNG and it worked.
I found the code to convert movieclip to bytearray in Stackoverflow itself
AS3: Export a 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 writeBytes function of buffer object. Assume that the name of the movieclip is canvas_mc.
I have figured out the php part already. Thanks in advance.
You don't use ByteArray.writeObject()
and parse a MovieClip
..
You need to use bitmapData.getPixels()
which returns a ByteArray
representing the pixels of your bitmap.
Here's a quick 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 what you want to do is use BitmapData.draw()
to get your MovieClip graphics and store them as a ByteArray.
精彩评论