I’m using some services of a web service which usually returns JSON respones, but one service when I send the ID of a user returns a static GIF image (Not animated).
The procedure that I’m doing is:
1.Connect to web service using DefaultHttpClient
2.Convert the InputStream received to a String with this utilitary method:
public static String inputStreamToStringScanner(InputStream in) {
Scanner fileScanner = new Scanner(in);
StringBuilder inputStreamString = new StringBuilder();
while(fileScanner.hasNextLine())
inputStreamString.append(fileScanner.nextLine()).append("\n");
fileScanner.close();
return inputStreamString.toString();
}
3.Storage the converted received String to process the server response.
For the Image Service, when I see the string converted, it begins like this:
“GIF89a?��?�� …”
It’s a static GIF file.
I’m not being able to show the image in a ImageView, I have tried different things that I found in the web:
public void onPhotoFinished (String responseData) {
InputStream is = new ByteArrayInputStream(responseData.getBytes());
Bitmap bm = BitmapFactory.decodeStream(is);
userImage.setImageBitmap(bm);
}
This is something else that I have also tried:
public void onPhotoFinished (String responseData) {
InputStream is = new ByteArrayInputStream(responseData.getBytes());
final Bitmap bm = BitmapFactory.decodeStream(new BufferedInputStream(is));
userImage.setImageBitmap(bm);
}
This also doesn’t works:
public void onPhotoFinished (String responseData) {
InputStream is = new ByteArrayInputStream(responseData.getBytes());
Drawable d = Drawable.createFromStream(is, "src name");
userImage.setImageDrawable(d);
}
Finally, this doesn’t work either:
public void onPhotoFinished (String responseData) {
Bitmap bm = BitmapFactory.decodeByteArray(responseData.getBytes(), 0, responseData.getBytes().length);
userImage.setImageBitmap(bm);
}
In Logcat I receive “decoder->decode returned false”
Nothing seems to work… any ideas of what is wrong?
Thanks!
Finally, I resolved it with FlushedInputStream and using directly the Input Stream, avoiding the conversion to String:
AND:
Regards