views:

270

answers:

1

Some of the images are not being displayed in the web browser in android while they work fine on all other machines and mobile devices.

this is an example of one of those images http://s3.amazonaws.com/itriage/logos/19/iphone_list.jpg?1261515055

So I tried to pull the image to see it if it works from code. This is what I did

URL url = new URL(address);
InputStream is = (InputStream) url.getContent();
Drawable d = Drawable.createFromStream(is, "src");

It works for most images but for some images including this images it gives this error

D/skia (28314): --- decoder->decode returned false

Why is this happening and how can I prevent this. I saw an example on the developers forum but thats when we are accessing the image directly. But what I want is the browser to handle it. So how do I encode my images on my server for the android devices to recognise them correctly?

A: 

The problem with your code is that Drawable.createFromStream() expects to be passed a resource stream - as in, data that comes from your /resources/ directory. I think you'd do better to use something based on BitmapFactory.decodeStream(); if you use a BitmapDrawable you can create a new one from an InputStream:

URL url = new URL(address);
InputStream is = (InputStream) url.getContent();
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), is);
Daniel Lew
Thank you for the answer,But like I said in my question itself, I am aware of that. What I want is the images to be displayed properly in the browser on an android device.I am using webviews to display my content and this is example of one of those images fail to be rendered. So I was wondering if there is any way to encode the images itself as I want all my images in from our server to be displayed properly on the android device.Still thank you for trying to help.
achie