0

I have this problem: I want represent a base64 string to image that come from php page in my android application (the string base64 work fine and come good) so I have done this:

byte[] gzipBuff = Base64.decode(json_data.getString("immagine"),0);
ByteArrayInputStream memstream = new ByteArrayInputStream(gzipBuff, 0, gzipBuff.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream(gzipBuff.length);
baos.write(gzipBuff);

Bitmap bmp = BitmapFactory.decodeStream(memstream);
ImageView image = new ImageView(this);
image.setImageBitmap(bmp);

I don't see the imageview

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Mrfalco
  • 1
  • 1
  • 2
  • 2
    Why are you creating a ByteArrayOutputStream? If this is gzipped, why are you not doing any kind of gzip decompression? Are you not seeing any exceptions? – Jon Skeet Mar 26 '11 at 09:25
  • the variable gzip is only variable if i mistake please tell me a solution because with other language like c# or vbnet i resolve very well and with few code because there i can use a memory stream so there i done : imagebyte=Convert.FromBase64(stringa); MemoryStream ms=new MemoryStream(imagebyte,0,imagebyte.Length); Image img=Image.FromStream(ms,True); this work very fine but in Android i don't know Can you help me? Thank's a lot – Mrfalco Mar 26 '11 at 09:49
  • 1
    @Mrfalco: I'd expect it to work, although there's no point in using `baos` in the code you've given. Again, I'd expect there to be an exception if anything's wrong with the data. Have you stepped through in a debugger to check that you're getting the right data? – Jon Skeet Mar 26 '11 at 10:01
  • this is the log 03-26 11:10:07.746: DEBUG/dalvikvm(2604): GC_EXTERNAL_ALLOC freed 1927 objects / 136160 bytes in 119ms 03-26 11:10:29.107: INFO/System.out(2604): resolveUri failed on bad bitmap uri: android.widget.ImageView@43e49590 03-26 11:10:29.467: INFO/ActivityManager(58): Displayed activity com.falco.mysql/.TestMysql: 51094 ms (total 51094 ms) – Mrfalco Mar 26 '11 at 10:13
  • @Mrfalco: You haven't answered whether you've inspected the data you're getting in the debugger. – Jon Skeet Mar 28 '11 at 18:37

1 Answers1

1

A quick Google search finds one of your other duplicate questions as the first result, and this as the second. See the accepted answer from that question.

Community
  • 1
  • 1
RivieraKid
  • 5,923
  • 4
  • 38
  • 47