Image is not loading when loaded using ImageLoader - android

I am trying to set an image from url using ImageLoader.
Here is my code
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.resetViewBeforeLoading(true)
.considerExifParams(true)
.showImageOnFail(R.drawable.no_image)
.showImageForEmptyUri(R.drawable.no_image)
.showImageOnLoading(R.drawable.no_image)
.displayer(new FadeInBitmapDisplayer(300))
.build();
// Stop running tasks on this image if there are unfinished some
ImageLoader.getInstance().cancelDisplayTask(mPostPhotoImageView);
// Load the image
ImageLoader.getInstance().displayImage(imageUrl, mPostPhotoImageView, options);
I don't understand, why is this happening.

Have you considered using the Picasso library?
I find it much easier to use to load images from an url, all you need is an imageView and url as arguments.
Picasso.with(context).load("URLHERE").into(imageView);
I'd also check your permissions, especially asking them on runtime, just in case (though this shouldn't be the issue)

Related

Different saving path for universal image loader

I am using 'universal image loader' library in my application to load images from internet. In some parts of my application I don't need to cache the images in memory for long time so I clear the cache every 24 hours. In other parts I need to cache images for long time and I don't want to clear them.
My question is, is it possible to config universal image loader some how to use different caching paths and the other question is how can I save the cached data in a custom folder ?
This is how I configure my uil :
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(false)
.cacheOnDisk(true)
.considerExifParams(true).build();
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
You may use different instances DisplayImageOptions. Something like this
cachedOnDiskOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(false)
.cacheOnDisk(true)
.considerExifParams(true).build();
cachedInMemoryOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_loading)
.showImageForEmptyUri(R.drawable.strawberry)
.showImageOnFail(R.drawable.image_faild)
.cacheInMemory(true)
.cacheOnDisk(false)
.considerExifParams(true).build();
ImageLoader.getInstance().displayImage(url, imageView, cachedInMemoryOptions);
ImageLoader.getInstance().displayImage(anotherUrl, anotherImageView, cachedOnDiskOptions);

Universal Image Loader not loading image for specific link

I started to use Universal Image Loader instead of Picasso, to avoid the image-not-loading problem. Now it emerges in Universal Image Loader too. It is the same problem with the same unique image, but not other images.
The problematic Image:
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4_4.jpg
Other properly-behaved images:
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.2_4.jpg
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.3_4.jpg
http://luxproperty.kaytami.com/platform/media/image/jpeg/2015/01/4.4_4.jpg
They are of similar sizes. And about my Universal Image Loader, the setting is as such:
In Application:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.diskCacheSize(50 * 1024 * 1024) // 50 Mb
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
In activity:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.image_placeholder)
.showImageForEmptyUri(R.drawable.image_error)
.showImageOnFail(R.drawable.image_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.build();
.......
ImageLoader.getInstance().displayImage(url), image, options);
Any hints would be much appreciated. I just cannot get rid of this problem anyhow, neither with Picasso nor Universal Image Loader.....
My previous StackOverFlow with Picasso:
Picasso cannot load images for some URL (no special characters)
It seems like the image is corrupted as downloading and opening it in photoshop also throws error. You can also see the bottom part of the image for blurry pixels.
Although there is one more case that I know of when image loading fails is when loading an image in CMYK color format. Android doesn't support CMYK, although there are some Third-party libraries for loading CMYK images but I don't think that it is the case for you. I strongly believe that the image is corrupted.
imageLoader = ImageLoader.getInstance();
prova = context;
options = new DisplayImageOptions.Builder()
//.displayer(new RoundedBitmapDisplayer(1000))
.showImageOnLoading(R.drawable.placeholder)
.showImageForEmptyUri(R.drawable.placeholder)
.showImageOnFail(R.drawable.placeholder)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
// .displayer(new RoundedBitmapDisplayer(70))//////
.build();
//note you use this in your adapter where your handling your image and make sure you inistalize that your UIL class in your manifest application
<application
android:name="com.example.UILApplication"

Expire UIL cached images after 2 days in android

I am using Universal Image Library (UIL) to load images in my application.
Now problem is that I can have different images on same URL. I mean today I have a cat picture in a URL and tomorrow I might have a dog picture on same URL. So I want to check that if cached image is 2 days old then delete it and download the image again.
This is my configuration.
File cacheDir = StorageUtils.getOwnCacheDirectory(this, "FriendListCache");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
// You can pass your own memory cache implementation
.diskCache(new UnlimitedDiscCache(cacheDir))
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
.build();
ImageLoader.getInstance().init(config);
And this is image loading options.
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.medium_load)
.cacheInMemory(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.decodingOptions(resizeOptions)
.displayer(new RoundedBitmapDisplayer(160))
.build();
UIL provide LimitedAgeDiscCache option for your requirement.
LimitedAgeDiscCache (Size-unlimited cache with limited files' lifetime. If age of cached file exceeds defined limit then it will be deleted from cache.)
.discCache(new LimitedAgeDiscCache(cacheDir, 14400))

Android: Loading Large Images with Universal Image Loader

I'm trying to make an activity like the image below. On the imageview with the viewpager I load some random images and also on the smaller ones. When someone clicks on the smalls I update the views with new images. My problem is that when I click more than three times after update the views on one of the smalls I get an OutOfMemory Exception. I understand that this caused by the bitmans and for that reason I set the Universal Image Loader to cache the images on the disk and not on memory. Also when someone press on one of the smalls I clear both memort and disc cache. But still I got the exception. Any ideas how to handle it?
Universal Image Loader Code
DisplayImageOptions options = new DisplayImageOptions.Builder()
//.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(_activity.getApplicationContext()).build();
ImageLoader.getInstance().init(config);
ImageLoader imageLoader = ImageLoader.getInstance();
Activity Style Image
try using
profile_options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.placeholder)
.showImageForEmptyUri(R.drawable.placeholder)
.showImageOnFail(R.drawable.placeholder)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
or download the latest version of universal lmage loader

Universal Image Loader not show images after remove internet

I found a problem using UIL. Steps to show error:
I download pictures on a screen
I remove internet
I'll be right back
And I go to the screen where I had downloaded the images.
The images are not displayed. But if I restart internet and get back into the screen, the images are displayed.
Is there any option to correct this error? thanks
Configuration:
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.imagen)
.showImageForEmptyUri(R.drawable.imagen)
.showImageOnFail(R.drawable.imagen)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.build();
This is not the problem. May your cache is clearing when you close application .
See My Configuration this might help you because at My side its Working.
options = new DisplayImageOptions.Builder()
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.NONE_SAFE)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();

Categories

Resources