android - Converting JSON object with Bitmaps -


i have object contains few string members , bitmap member.

the object held in map string key , object value.

i'm using following code convert map:

string json = new gson().tojson(amap); 

and extract json map use (passing above json string):

map<string, object> amap;     gson gson = new gson();     amap = gson.fromjson(jsonstring, new typetoken<map<string, object>>() {}.gettype()); 

this partially works bitmap stored in object appears corrupted? i.e. when try apply bitmap image view exception.

i'm thinking may need separately convert bitmap string json hoping theres simpler solution, ideas?

thanks.

this simple :

private string getstringfrombitmap(bitmap bitmappicture) {  /*  * functions converts bitmap picture string can  * jsonified.  * */  final int compression_quality = 100;  string encodedimage;  bytearrayoutputstream bytearraybitmapstream = new bytearrayoutputstream();  bitmappicture.compress(bitmap.compressformat.png, compression_quality,  bytearraybitmapstream);  byte[] b = bytearraybitmapstream.tobytearray();  encodedimage = base64.encodetostring(b, base64.default);  return encodedimage;  } 

and vice versa:

private bitmap getbitmapfromstring(string jsonstring) { /* * function converts string bitmap * */ byte[] decodedstring = base64.decode(stringpicture, base64.default); bitmap decodedbyte = bitmapfactory.decodebytearray(decodedstring, 0, decodedstring.length); return decodedbyte; } 

this not mine, took here.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -