0

I am trying to post my phone contact details like name,number,email,address and photo to the webserver in json fromat,where the image is encoded in Base64 format. In server side the image is being stored as BLOB type in the database. I'm trying to retreive and display all the data from the server in a listview. I am able to display all data except image.

Here is the code:

For Encoding the image:

ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
                          bitmap.compress(Bitmap.CompressFormat.PNG, COMPRESSION_QUALITY, byteArrayBitmapStream);
                          byte[] b = byteArrayBitmapStream.toByteArray();
                          String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

jsonObject.accumulate("imageData",encodedImage);

For Decoding the image:

String image=(String)jsonObject.get("image");
byte[] byteArray =  Base64.decode(jsonObject.getString("imageData").getBytes(), Base64.DEFAULT) ;

Bitmap bmp1 = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_IMAGE,bmp1);

Please help me out to display the image in listview.Thanks...

Error Log:

12-16 12:07:58.403: E/BitmapFactory(1072): Unable to decode stream: java.io.FileNotFoundException: /android.graphics.Bitmap@40f67ac0: open failed: ENOENT (No such file or directory)
12-16 12:07:58.423: I/System.out(1072): resolveUri failed on bad bitmap uri: android.graphics.Bitmap@40f67ac0
Pavel Oganesyan
  • 6,774
  • 4
  • 46
  • 84
user2879697
  • 69
  • 1
  • 10

2 Answers2

1

I think you should use Universal Image Loader for Android library.

This will do all complex stuff for you to display image from web server with many customization option.

Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76
  • Thanks for your answer. But I'm not taking any image url.. I'm storing the image as BLOB type in database. How can I do without fetching back the image url? – user2879697 Dec 16 '13 at 07:44
0

I think you should download lazy loader

This will all complex stuff for you to display image from webserver

The Ray of Hope
  • 738
  • 1
  • 6
  • 16