0

I have done the retrieving 100 images URL from JSON. And i want to display in Image Gallery in my Android application. I have tried convert into bitmap but it returns null:

(--- SkImageDecoder::Factory returned null )

Can someone help me for how to convert multiple images url in bitmap.

Here is my code

private class DownloadJSON extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        mProgressDialog = new ProgressDialog(TrustMe.this);
        mProgressDialog.setTitle("Android JSON Parse Tutorial");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        getImagesfromServer();
        return null;
    }

    @Override
    protected void onPostExecute(Void args)
    {
        mProgressDialog.dismiss();

        for (int j = 0; j < arraylist.size(); j++)
        {
            Iterator<String> myVeryOwnIterator = map.keySet().iterator();
            while (myVeryOwnIterator.hasNext()) {
                String key = (String) myVeryOwnIterator.next();
                String value = (String) map.get(key);
                byte[] decodedString = Base64.decode(value,
                        Base64.DEFAULT);
                decodedByte = BitmapFactory.decodeByteArray(
                        decodedString, 0, decodedString.length);

                bitimg.add(decodedByte);
            }
        }

        gallery = (Gallery)findViewById(R.id.galleryImg);
        _imageAdapter = new ImageAdapter(TrustMe.this);
         if (_imageAdapter == null) {
              _imageAdapter = new ImageAdapter(getApplicationContext());
              gallery.setAdapter(_imageAdapter);
         }
        _imageAdapter.setimage(bitimg);
        _imageAdapter.notifyDataSetChanged();
   }
}

Here is JSON Data

05-16 13:04:08.449: I/System.out(686): strID = 259429316
05-16 13:04:08.459: I/System.out(686): jarr  = {"large_thumb":{"url":"http:\/\/thumb9.shutterstock.com\/thumb_large\/612877\/259429316\/stock-photo-cat-with-a-bouquet-at-the-feet-of-mistress-259429316.jpg","width":150,"height":100},"preview":{"url":"http:\/\/image.shutterstock.com\/display_pic_with_logo\/612877\/259429316\/stock-photo-cat-with-a-bouquet-at-the-feet-of-mistress-259429316.jpg","width":450,"height":299},"small_thumb":{"url":"http:\/\/thumb9.shutterstock.com\/thumb_small\/612877\/259429316\/stock-photo-cat-with-a-bouquet-at-the-feet-of-mistress-259429316.jpg","width":100,"height":67}}
05-16 13:04:08.468: I/System.out(686): strID = 256797013
05-16 13:04:08.468: I/System.out(686): jarr  = {"large_thumb":{"url":"http:\/\/thumb10.shutterstock.com\/thumb_large\/1477187\/256797013\/stock-photo-beautiful-woman-with-cat-portrait-brunette-with-bengal-cat-close-up-256797013.jpg","width":150,"height":100},"preview":{"url":"http:\/\/image.shutterstock.com\/display_pic_with_logo\/1477187\/256797013\/stock-photo-beautiful-woman-with-cat-portrait-brunette-with-bengal-cat-close-up-256797013.jpg","width":450,"height":300},"small_thumb":{"url":"http:\/\/thumb10.shutterstock.com\/thumb_small\/1477187\/256797013\/stock-photo-beautiful-woman-with-cat-portrait-brunette-with-bengal-cat-close-up-256797013.jpg","width":100,"height":67}}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
JAndroid
  • 1
  • 1
  • See this answer http://stackoverflow.com/questions/30256060/converting-image-url-to-bitmap-quickly/30256138#30256138 – theapache64 May 16 '15 at 05:33
  • `I have done the retrieving 100 images URL from JSON.`. ????? Sorry, i do not understand a word of it. Please explain what you want to do or have done exactly. – greenapps May 16 '15 at 06:56
  • @JAndroid Are the urls in base64 format? please provide a sample of your JSON data. – aliep May 16 '15 at 07:05
  • I fetch 100 image URL from the back end server and parsing the JSON. But right now I want to convert into bitmap and set it to Image-view .I have try for single image its work perfectly , but the problem is how to convert all 100 image URL into bitmap and set it into image gallery. I tried with for loop but in log cat shows = (--- SkImageDecoder::Factory returned null ) – JAndroid May 16 '15 at 07:08
  • This JSON Data = 05-16 12:38:01.139: I/System.out(650): jarr = {"large_thumb":{"url":"http:\/\/thumb1.shutterstock.com\/thumb_large\/1708531\/248009440\/stock-photo-flying-seagulls-248009440.jpg","width":150,"height":96},"preview":{"url":"http:\/\/image.shutterstock.com\/display_pic_with_logo\/1708531\/248009440\/stock-photo-flying-seagulls-248009440.jpg","width":450,"height":287},"small_thumb":{"url":"http:\/\/thumb1.shutterstock.com\/thumb_small\/1708531\/248009440\/stock-photo-flying-seagulls-248009440.jpg", – JAndroid May 16 '15 at 07:11
  • `I fetch 100 image URL from the back end server`. Very unclear. But after your last comment it looks as if you ment `I fetch a json text from a server which contains 100 image url's`. Please post that json text in your post. Comments are unsuitable for such. – greenapps May 16 '15 at 07:24
  • @greenapps : ok just minute – JAndroid May 16 '15 at 07:33
  • I have post JSON Data above. – JAndroid May 16 '15 at 07:36
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). BTW, it's "Thanks in advance", not "Thanks in advanced". – John Saunders May 22 '15 at 21:37

2 Answers2

0

Use this,

URL newurl = new URL(imageLink);
Bitmap image = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
Exigente05
  • 2,161
  • 3
  • 22
  • 42
0

One advice, decode all your bitmap in doInBackground() rather than onPostExecute(), Bitmap-decoding is also a time comsuming work, and it seems you saved all your images in memory in Base64-converted form? Why not just save them as cache on disk?

jobcrazy
  • 1,073
  • 10
  • 16