I need to be able to load a jpeg/png image from disk and show it in flex and send it to a server as a base64 encoded string. But once the image file is loaded, in my flash.display.LoaderInfo
object, the bytes
property (type of ByteArray
) contains more byte than the file content.
Example: image file size: 3089 flash.display.LoaderInfo.bytesTotal:3089 flash.display.LoaderInfo.bytes.length:3155
As i need to encode the flash.display.LoaderInfo.bytes
in base64 string, i don't know which part of the ByteArray objet i must send to server.
I don't want to draw the bytearray content into a Bitmap image and re-encode it as jpg because i must keep the original quality of the file.
Thanks
some code:
private function onDataLoadComplete(event:Event):void {
var encoder:Base64Encoder = new Base64Encoder();
//var imagePartBytes:ByteArray = new ByteArray();
//imagePartBytes.writeBytes(event.target.bytes, 0, event.target.bytesTotal);
//imagePartBytes.writeBytes(event.target.bytes, 0, event.target.bytes.length);
//imagePartBytes.writeBytes(event.target.bytes, event.target.bytes.length-event.target.bytesTotal, event.target.bytesTotal);
encoder.encodeBytes(event.target.bytes);
var imagePart:String = encoder.flush();
trace(imagePart);
data = fileName+";"+event.target.contentType+";"+imagePart;
_changed = true;
}