Android-Universal-Image-Loader icon indicating copy to clipboard operation
Android-Universal-Image-Loader copied to clipboard

Can't load image from Content Provider

Open MikeWallaceDev opened this issue 12 years ago • 36 comments

Hello,

I'm having a weird problem. I have two apks, one is a Content Provider and the other consumes the data. The following code in the consumer does not work:

imageLoader.displayImage("content://com.risesoftware.coloroos_animals/assets/aa.png", imgvw_page);

The error is :

E/ImageLoader﹕ Image can't be decoded [content://com.risesoftware.coloroos_animals/assets/aa.png_1000x1000]

but the following code DOES work :

Uri theUri = Uri.parse("content://com.risesoftware.coloroos_animals/assets/aa.png");
InputStream inputStream = null;
inputStream = m_context.getContentResolver().openInputStream(theUri);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imgvw_page.setImageBitmap(bitmap);

I looked through BaseImageDownloader and the code is virtually identical.

MikeWallaceDev avatar Feb 17 '14 20:02 MikeWallaceDev

Yes, it's weird. Show your configuration and display options.

nostra13 avatar Feb 20 '14 10:02 nostra13

defaults...

  ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(getApplicationContext())
              .build();

  ImageLoader.getInstance().init(config);

DisplayImageOptions m_options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_loading) .build();

MikeWallaceDev avatar Feb 20 '14 15:02 MikeWallaceDev

Which UIL version do you use? Show more logs.

nostra13 avatar Feb 20 '14 15:02 nostra13

Sorry about not giving more information, it's because I'm at a loss myself and don't know from where to start! As far as I am concerned, it should work. I thought maybe the context of using a Content Provider from another application might put you on the trail of something...

compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.+'
com.risesoftware.coloroos D/libEGL﹕ loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
com.risesoftware.coloroos D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
com.risesoftware.coloroos D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
com.risesoftware.coloroos D/OpenGLRenderer﹕ Enabling debug mode 0
com.risesoftware.coloroos D/ColoringPagesAdapter﹕ content://com.risesoftware.coloroos_main/assets/coloringPages/Tweety-Bird.png
com.risesoftware.coloroos D/skia﹕ --- SkImageDecoder::Factory returned null
com.risesoftware.coloroos E/ImageLoader﹕ Image can't be decoded [content://com.risesoftware.coloroos_main/assets/coloringPages/Tweety-Bird.png_1000x1000]

I hope that this helps...

MikeWallaceDev avatar Feb 20 '14 16:02 MikeWallaceDev

I can't see any useful information in UIL from the above loggings...

bytebeats avatar Feb 21 '14 01:02 bytebeats

You sure your url of this image is OK then?

bytebeats avatar Feb 21 '14 01:02 bytebeats

I am very sure, as I wrote in the initial post the other code does indeed work. At this moment I have the UIL code commented out and the other code uncommented and the app works. The images load, the listview scrolls, everything works. But of course it's jittery which is why I want to use UIL. The only difference that I can think of between the two snippets of code is that the native code takes a URI and UIL takes a string. Can there be a difference in the URI format that UIL requires? (I don't think so, I am just grasping at straws here...)

since it's gotten this far, here is the exact code, copy pasted from my sources...

   public View getView(int position, View convertView, ViewGroup parent)
   {
      ViewHolder viewHolder = null;

      if (null == convertView) {
         convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listitem_coloring_pages, null);

         viewHolder = new ViewHolder();
         viewHolder.imgvw_page = (ImageView) convertView.findViewById((R.id.imgvw_page));
         convertView.setTag(viewHolder);
      }
      else {
         viewHolder = (ViewHolder)convertView.getTag();
      }

      final long coloringBookId = m_coloringPages.get(position).m_coloringBookId;

      //fixme stringbuilder
      StringBuilder uriBuilder =
            new StringBuilder("content://")
                  .append(m_coloringBooks.get(coloringBookId).m_bookUri)
                  .append("/assets/coloringPages/")
                  .append(m_coloringPages.get(position).m_filename);

      Uri theUri = Uri.parse(uriBuilder.toString());
      Log.d(TAG, theUri.toString());

//      m_imageLoader.displayImage(uriBuilder.toString(), viewHolder.imgvw_page);

      InputStream inputStream = null;
      try {
         inputStream = m_context.getContentResolver().openInputStream(theUri);
         if (null != inputStream) {
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            viewHolder.imgvw_page.setImageBitmap(bitmap);
         }
      }
      catch (FileNotFoundException e) {
         e.printStackTrace();
      }
      finally {
         if (null != inputStream) {
            try {
               inputStream.close();
            }
            catch (IOException e) {
               e.printStackTrace();
            }
         }
      }

      return convertView;
   }

MikeWallaceDev avatar Feb 21 '14 13:02 MikeWallaceDev

bump :)

MikeWallaceDev avatar Feb 25 '14 14:02 MikeWallaceDev

Try to pass the following decoding options into display options:

Options decodingOptions = new Options();
DisplayImageOptions m_options =
 new DisplayImageOptions.Builder()
 .showImageOnLoading(R.drawable.ic_loading)
 .decodingOptions(decodingOptions)
 .imageScaleType(ImageScaleType.NONE)
 .build();

nostra13 avatar Mar 04 '14 20:03 nostra13

I can't try at this moment, but I will. Thank you very much :)

MikeWallaceDev avatar Mar 04 '14 20:03 MikeWallaceDev

Ok Sergey, sorry that it took two days, but I was able to try it. It didn't work, same stack trace.

MikeWallaceDev avatar Mar 06 '14 19:03 MikeWallaceDev

I met this problem when i read images from sdcard ,and i trid to pass decoding options into display options , i can still get this issue sometime.

xxnjdlys avatar May 12 '14 12:05 xxnjdlys

I'm also having this issue. Has anyone figured out a solution? It's not happening to every image, but about 30% of them. All the log says is "Image can't be decoded"

nachtien avatar Jun 02 '14 15:06 nachtien

I have the similar issue, after playing around with ImageLoaderConfiguration options, I decided to turn off .cacheOnDisk(false) then, images will display ok.

Thanks

lunf avatar Jun 14 '14 16:06 lunf

I'm having the same issue and turning off the disk caching is not an option for me.

This only happens on 1 phone out of all of our test devices: HTC Desire HD running 2.3.3. All others are fine. This must be either how gingerbread stores/loads things from disk on how this particular device does it.

This only happens with specific images, not all of them.

ghost avatar Jun 23 '14 18:06 ghost

any advancement people ? facing same issue here too!

sud007 avatar Jun 30 '14 05:06 sud007

I accidentally found some dirty hacked on this issue. I have tried all settings combination and it do not works out, so I put two image loading methods as following:

            ImageLoader.getInstance().displayImage(itemData.getImage(), viewHolder.imageView);

            ImageLoader.getInstance().loadImage(itemData.getImage(),imageSize, AppEngine.getDefaultImageOptions(),new SimpleImageLoadingListener(){
                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    super.onLoadingComplete(imageUri, view, loadedImage);
                    viewHolder.imageView.setImageBitmap(loadedImage);
                }

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    super.onLoadingStarted(imageUri, view);
                }
            });

All the missing images appear again.

lunf avatar Jun 30 '14 08:06 lunf

Please fix the issue. I don't know why the library is appending _480x800 at the end of image url. @lunf None of your methods are working.

frodberserk avatar Jul 10 '14 10:07 frodberserk

It's not appending the size at the end of the URL. That's just for reference.

On Thu, Jul 10, 2014 at 5:41 AM, frodberserk [email protected] wrote:

@lunf https://github.com/lunf None of your methods are working. Please fix the issue. I don't know why the library is appending _480x800 at the end of image url.

— Reply to this email directly or view it on GitHub https://github.com/nostra13/Android-Universal-Image-Loader/issues/539#issuecomment-48589426 .

nachtien avatar Jul 10 '14 21:07 nachtien

try to your url String trim()

choHJ avatar Jul 15 '14 07:07 choHJ