Can't load image from Content Provider
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.
Yes, it's weird. Show your configuration and display options.
defaults...
ImageLoaderConfiguration config =
new ImageLoaderConfiguration.Builder(getApplicationContext())
.build();
ImageLoader.getInstance().init(config);
DisplayImageOptions m_options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_loading) .build();
Which UIL version do you use? Show more logs.
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...
I can't see any useful information in UIL from the above loggings...
You sure your url of this image is OK then?
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;
}
bump :)
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();
I can't try at this moment, but I will. Thank you very much :)
Ok Sergey, sorry that it took two days, but I was able to try it. It didn't work, same stack trace.
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.
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"
I have the similar issue, after playing around with ImageLoaderConfiguration options, I decided to turn off .cacheOnDisk(false) then, images will display ok.
Thanks
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.
any advancement people ? facing same issue here too!
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.
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.
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 .
try to your url String trim()