i have to send my data using json and have to send image using byte[] in my json. Now I can get the bitmap to convert to bytearray using the following line of codes:
selectedImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100,stream);
byte[] byteArray = stream.toByteArray();
But I cant put this byte array in Json. I am using android 2.1 default Json object. When I try to convert byte[] to JSONArray, it gives me Out of memory exception.
JSONArray jsonArray = new JSONArray();
for(int i=0;i<byteArray.length;i++) {
jsonArray.put(byteArray[i]);
}
When I try to put the object directly in JsonObject, it returns a weird hex string in toString() (probably the objects memory location).
Can anybody please help me out with this. Is there a standard way to put a byte[] in json??
P.S: I tried using base64 initially. But that frequently cause Out of Memory exceptions as the images i have to send and recieve are large and thus there base64 is large too!