views:

23

answers:

0

Hi everyone!

I'm currently trying to create a gallery of pictures loaded from Internet.

I'm using a standard Gallery object, with a custom adapter and a custom ImageView. Everything is working quite fine, expect for the pictures downloading.

I'm using an asynchronous task to do this (I have thumbnails displaying while loading).

It's working really well to load thumbnails, but not really for the "big" images (about 50k each).

I'm using this for loading pictures :

private class DownloadImageTask extends AsyncTask<String,Void,Drawable>{

    @Override
    protected Drawable doInBackground(String... arg0) {
        URL url;
        InputStream is;
        Drawable d=null;
        try {
            url = new URL(arg0[0]);
            is = (InputStream) url.getContent();
            d = Drawable.createFromStream(is, "src");
            return d;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(Drawable result) {
        setImage(result);
    }

}

Problem is, quite randomly but about 8 times out of 10, I got the following message in my log "10-25 14:58:18.764: DEBUG/skia(11294): --- decoder->decode returned false", and then my drawable is null.

I'd say there is a problem with my code, but why is it working sometimes? or not?

I tried to put WebViews in my gallery, loading only the image URL, and it's working really nicely and awsomly fast to download the pictures, but then the display is quite messed up (slower and not responsive, and images are not centered in the screen...).

What should I do?

I don't understand why sometimes my inputstream is not working. Only sometimes. If tried hard enough (like with a loop), it always works after a few attemps, but it's really an ugly solution.

Is there a way to download the pictures with webviews and get them after? I tried something like that (with getCache() or capturePicture() from the webview) but it wasn't showing anything...

Any thoughts? Any ideas?

Thanks a lot!

EDIT: Well.. it's working everytime when I realize a copy of the inputStream... but why?