Reputation: 365
i have to save a bitmap in to a sharedobject....I read it online that inorder to do that I would have to convert into a bytearray..but I ma not sure how to do this...can somebody please explain to me a little step by step on how to convert a bitmap into bytearray..
this is the code i am working with
var btm:BitmapData;
var x_d:Array = new Array();
orange.addEventListener( MouseEvent.CLICK, firstc);
function firstc (x:MouseEvent){
btm = new BitmapData(200,200);
x_d[0] = new Bitmap (btm);
addChild(x_d[0]);
btm.draw (orange);
gotoAndStop(3);
};
Upvotes: 1
Views: 5866
Reputation: 91
If you want raw data you should use getPixels() method but if you want to store bitmapdata compressed as jpg or png do like this:
PNG
btm = new BitmapData(200,200);
...
var stream:ByteArray = PNGEncoder.encode( btm );
JPG
btm = new BitmapData(200,200);
...
var jpgEncoder:JPGEncoder = new JPGEncoder( 90 );
var stream:ByteArray = jpgEncoder.encode( btm );
for PNGEncoder and JPGEncoder classes use as3corelib
If you target users with Flash Player 11.3 and above you can use native encoder
Upvotes: 3