I'm loading images using Glide this way in a Fragment
Glide.with(this).load(pictureUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.default)
.into(image);
but the image is never set into the ImageView although the image IS indeed being loaded (I investigated this using a listener). I believe this only happens when the image is not being loaded from memory since it does load if the Fragment is resumed.
If I add asBitmap() above, then the image successfully loads. Also, setting the GlideDrawable into the ImageView from an attached RequestListener's onResourceReady() method also works.
For anyone else with a similar problem, it turned out to be related to a custom View. See the post on the discussion list for more information.
Related
I have an issue with Glide. In the first fragment I have a stack of views with background loaded with Glide. In the second fragment there is recyclerview with this kind of views. But when I navigate to the second fragment the background flickers. I tried to remove animation and change disk cache strategy, but without success. I am loading background with this
Glide.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.dontAnimate()
.listener(listener)
.into(imageView)
When I tried to investigate, I found that the flicker occurs when the image is loaded from disk cache. For the second time, it loads from memory cache and everything is ok. I think the problem occur because of views' different size. But do not have clue to solve the issue.
I am working on an application that has this image gallery activity where images are loaded from disk using Glide. These images are downloaded separately through DownloadManager. The problem is that these images might not have been downloaded by the time the user opens the gallery. I guess one way would be to load these images dynamically once each file gets downloaded by going through a BroadcastReceiver but I am wondering if there is an easier solution? Some of the images only shows parts of itself while others don't show at all, and in order to view the full images I have to navigate back into the gallery so that Glide can redo the loading. I would instead like the images to be displayed once they are able to load. I also tried using a placeholder but it will never be replaced by the image (I would also like to avoid using a placeholder image since I don't have any). The images are displayed in a GridView and loaded in getView method of a BaseAdapter. (Currently I also have to avoid storing the images in cache otherwise the incomplete images will be shown the next time as well). Code:
val file = File(urls[position].toString())
Glide.with(context)
.asBitmap()
.load(file)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.fitCenter()
.apply(RequestOptions())
.into(imageView)
I am storing my image and its reduced size image (blurred) in my Amazon Server, and store both path in database.
Now I want to know how to show blurred image first if original image is not cached and on clicking download it will download original Image. I am using Glide here...
I tried this
Glide.with(this)
.load(mainUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.thumbnail(Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE))
.centerCrop()
.into(imageView);
but problem is It automatically download original image in background.
I asked in Glide Github.
https://github.com/bumptech/glide/issues/2051
So add apply(RequestOptions.onlyRetrieveFromCache()) to your RequestOptions. You can register a listener and onFailed gets called when no image is in the cache.
Glide.with(TheActivity.this)
.load("http://sampleurl.com/sample.gif")
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(theImageView);
Your code will prevent Glide from downloading the GIF and will only show the GIF if it is already cached, which it sounds like you don't want.
Yes, the old image will eventually be removed. By default Glide uses an LRU cache, so when the cache is full, the least recently used image will be removed. You can easily customize the size of the cache to help this along if you want. See the Configuration wiki page for how to change the cache size.
Unfortunately there isn't any way to influence the contents of the cache directly. You cannot either remove an item explicitly, or force one to be kept. In practice with an appropriate disk cache size you usually don't need to worry about doing either. If you display your image often enough, it won't be evicted. If you try to cache additional items and run out of space in the cache, older items will be evicted automatically to make space.
If you want to show placeholder before image is loading then use code below:-
Glide.with(this)
.load(mainUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder("provide placeholder image here")
.thumbnail(Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE))
.centerCrop()
.into(imageView);
I have a wrapper class that contains the ImageCardView and loads an image fetched from the Web into it. Before the network call is made, I have
imageCardView.getMainImageView().setImageResource(R.drawable.icon_movie_placeholder);
For some reason, the image never comes up if I have the network call take place right afterwards, even though it takes maybe .5-1.5 seconds for an individual poster to come up. But if I comment out the network call and assignment, the image comes up. How do I make it so that the placeholder is visible while the poster is being fetched? I use Picasso to do this, does Picasso clear the image view before it loads?
I think Picasso does clear the image when you call the load(url).into(imageView) method in order to avoid displaying incorrect images on a listView/recyclerView.
What you could use is Picasso's own way of setting a placeholder image, which works like this
Picasso.with(context)
.load(imageUrl)
.placeholder(R.drawable.icon_movie_placeholder)
.into(imageView)
This way Picasso will show your icon_movie_placeholder drawable until the network request finishes, and if you need to provide a placeholder image you can use the builder's error(resourceId) method just like that.
You can find more info about this on Picasso's official Github page (specially under the Features section: http://square.github.io/picasso/
Glide not loading image from memory at the first time when rotating (orientation change), and after that it is loading from memory.
I have tried to increase the memory size, the bitmap pool size, all kinds of caching strategies... nothing seemed to work...
I have attached a video.
https://youtu.be/szDnAGxrJLU
Thanks!
.dontAnimate() adding this to Glide solved my problem
Glide.with(view.getContext())
.load(url)
.placeholder(placeholder_image_crop))
.dontAnimate()
.into(view)
You may face this issue because of
CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.
for more queries refer following links it may help you.
link 1 and link 2
Your ImageViews don't have the exact same size in portrait and in landscape and you are probably using fitCenter() or centerCrop() to resize the image to the ImageView size. When you change orientation, Glide loads the full-sized image from cache but it has to resize it on a background thread first before display, that's why you see a delay after the first orientation change. After resized images for both portrait and landscape are in the memory cache, there is no more delay.
Just to emphasize what is written above and add a solution.
It is possible to change the disk caching strategy to cache the source image but not the memory caching strategy, in that case it will not hit unless it is the same size.
What i did was use .override(width,height) in order to override this strategy and keep the source image in the memory cache.
Glide.with(context)
.load(imgUrl)
.crossFade()
.override(imageWidth,imageHeight)
.into(imgView);
To load image from cache you can pass DiskCacheStrategy.SOURCE to load images from cache.
You can use glide like below and keep don't animate method as it helps to load images in adapter without updating full list. For more check this
Glide.with(context)
.load(row_object.getImage())
.dontAnimate() // will load image
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(ContextCompat.getDrawable(context,
R.mipmap.ic_user_placeholder_50dp))
.into(holder.rowIvPostUserIcon);
This code help me:
Glide.with(view.getContext())
.load(url)
.placeholder(AppCompatResources.getDrawable(view.getContext(), R.drawable.vector_placeholder_vendor_image_crop))
.dontAnimate()
.into(view);
//need add .dontAnimate()
For more information:
https://github.com/bumptech/glide/issues/1026#issuecomment-191709837
First Time glide is unable to load image on custom view like circular Imageview.you Can use error to load image on first time.
The following snippet should help you:
Glide.with(context)
.load(imgUrl)
.crossFade()
.override(imageWidth,imageHeight).error(R.drawable.yourdrawable)
.into(imgView);