views:

37

answers:

1

I am trying to serialize a Bitmap to store in an XML file. My plan is to turn the BitmapData into a byteArray, but I haven't been able to fine an example of this.

Other suggestions are also welcome.

+3  A: 

The process should be: BitmapData > ByteArray > Base64 > XML

Use the BitmapData getPixels() method to get a ByteArray of the pixels.

Then you can use something like Hurlant's Base64 encoder to convert it to base 64.

Then going the other way, "unbase64" it, then use BitmapData's setPixels to load it.

Ben
+1. Although it was not mentioned in the question, I wouldn't store the raw pixels. PNG would be a good fit here if the image data is going to be compressed and decompressed back and forth (using PNGEncoder from adobe as 3 lib for compressing and Loader.loadBytes for decompressing).
Juan Pablo Califano
@juan. Absolutely right, plenty of room for improvement.
Ben