I have from AS3 AIR App to send an image, beside rest of POST parameters to the PHP script which will do the rest. I want to somehow convert byte array with image to string and encode it with base64. I was successfull, but image data is wrong.
Here is the code I used to convert it:
...
//BA1 is Byte Array with an image in it
var data:String = BA1.toString();
OutSql.push({t: "b1", v: Base64.encode(data)});
...
Everything works fine, this data is sent to server, decoded, and stored as an image, but image is wrong. Somehow it is about 40 kb, while when I save it within Air application it is 22 kb. Any ideas?
p.s. I know that I can save it localy and upload it, but I really need to do it this way. Also, BA1.readUTF() generates an error, so not an option.
Addition:
On a server side I have tried to utf8_decode string before writing to file, and somehow I got an image which is proper dimensions, but... that image is not what I wanted to be, it looks like scribble...
BA1contain data of jpeg or png or just raw bitmapData (usedgetPixels();for bytes)? If its already jpg/png then useBase64.encode(BA1)then the B64 itself will give you an encoded string from the bytes. Anyway your size is 40kb (from 22kb) cos you usedtoString. Consider two bytes 0xFF and 0xD8 (total size is 2) now as a string it is FFD8 which is total size 4. The conversion is doubling the size. If possible just do atrace ("bytes are : " + BA1);then show me here the first 8 letters of the BA1 bytes. Easier to assess the format that way...bytes are : ÿØÿàJFIFÿÛwhich looks like a good jpeg header. But the rest of data is just messed up. Image siye is correct, by the way.