I've been trying to use BitmapFactory decodeStream() to load jpegs
from Flickr. This code works in the emulator but returns null when run
on my MyTouch3g:

URL url = new URL(sourceUrl);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 32000);

bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();


Looking at the approach used by Romain's Photostream browser app, the
code is using BitmapFactory.decodeByteArray() instead.

I've swapped out the code above for the snippet of code used in
Romain's app, and now this approach works on both the emulator and the
phone:

in = new BufferedInputStream(new URL(sourceUrl).openStream(),
    IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);


So question is, why doesn't the code above (at the top) work on the
phone, and what's different with the decodeByteArray() approach?

Thanks!

Kevin Hooke
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to