6

Edit: When I save those bytes in the txt file and when I save it as png file , it shows the image, but it is not working here why...?

I am using this code to create image from byte array on doInBackground()

String base64data=StringEscapeUtils.unescapeJava(IOUtils.toString(resp.getEntity().getContent()));
base64data=base64data.substring(1,base64data.length()-1);
JSONObject obj=new JSONObject(base64data);
JSONArray array=obj.getJSONArray("EMRTable");
JSONObject childobj=array.getJSONObject(0);
results=childobj.getString("DocumentInternalFormat");

and onPostExecute

if(jsondata!=null) {
    receiveData(jsondata);
}

There is no error in the logcat, even there is no exception in it..but the image isn't showing. I have also did like this

String data=(String)object;
data=data.trim();
byte[] base64converted=Base64.decode(data,Base64.DEFAULT);          

ImageView image=new ImageView(context);
image.setImageBitmap(bmp);
setContentView(image);

but the result same image isn't showing but there is no exception or an error, what is the problem...

The commented lines are when I try to store those bytes into text file and when I pull the file, it shows the images with windows default image viewer.

CraftedGaming
  • 499
  • 7
  • 21
Pragnani
  • 20,075
  • 6
  • 49
  • 74
  • 5
    Downvoters should tell the valid reason for giving the downvote...If you don't know the answer than don't respond...Without adding comment and without understanding the question how do you give a downvote.. – Pragnani Feb 05 '13 at 06:27
  • 2
    Upvote from me for a valid question. – harsimranb Feb 14 '13 at 21:35

2 Answers2

9

Try this code while getting bitmap from different resources...

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(base64converted,0,base64converted.length,options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, 500, 500);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bmp1=BitmapFactory.decodeByteArray(base64converted,0,base64converted.length,options);

follow the tutorial on this link Efficient way to show bitmaps

CraftedGaming
  • 499
  • 7
  • 21
-2

remove the below line from your code and try again

base64data=base64data.substring(1,base64data.length()-1);
V.J.
  • 9,492
  • 4
  • 33
  • 49
  • Thats not the problem, json data is surrounded by quotes, that's why i have removed the quotes, without that I can't create jsonObject...everything goes well, data coming,jsonobject, byte array everthing goes well but image isn't showing. – Pragnani Feb 04 '13 at 06:53