Wednesday, April 28, 2010

How to convert an image coming in base64 from webservice into bitmap

byte [] Decoded = Base64InputStream.decode(getNodeValue(detailNode), 0, getNodeValue(detailNode).length());
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
Bitmap bmp = bitmap.getBitmap();
add( new BitmapField(bmp));

Note:- here getNodeValue(detailNode) is a method which reads nodes of Web Service

2 comments:

  1. Hi! Do you have a video tutorial for this one? I tried to follow the script but I am having so much problems with it. I am not getting it.. :( do you have a video tutorial of this version instead? I need this up and running because I am working on a project and I need someone to help me out in the conversion. thanks in advance.

    Image Convert

    ReplyDelete
  2. Hi Aman. I didn't think it would be this easy - thanx for the tip.

    I wonder if there is any need for the 2 lines that convert 'byte[] Decoded' into 'dataArray'. In my current solution I was able to remove those 2 lines without any (current) problems.

    Anyway thanks again - a code sample that works 1st time round is valuable.

    ReplyDelete