Glide loads images slowly - android

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.

Related

How to show Glide images when ready? They are shown incorrectly if not fully downloaded

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)

Glide not loading image from memory at the first time when rotating (orientation change), and after that it is loading from memory

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);

ListView images preloading im ImageView without delay (using Picasso or other libs)

I have the problem with image loading in listview. I'm using Picasso to load pictures from network into my imageViews in each row. When I'm scrolling first time there always white background before image loaded in its place. Even if I scroll very slow or even stop scrolling before new item is showing, there still white background showing before the image is loaded. Even if these pictures wasn't taken from the network, but already from cache (yellow indicator). But when these pictures already in memory (green indicator) pictures don't loading each time when scrolling, they already loaded into imageView, so I don't have this white background (or it may appear on fast scrolling, but it's ok).
This how I use Picasso in my adapter:
Picasso.with(context).load(url).fit().centerCrop().into(imageView);
I know this is complicated topic and we can have OOM, but there should be some variants, as I can see it implemented in popular social networks, so I guess it possible.
P.S. fetch() doesn't helped me in this case, changing fit() with harcoded resize(200, 200) method also doesn't helped.
Please write your thoughts without silent minusing this post. Thanks!
Picasso.with("Pass Context") //
.load("Pass URL") //
.transform(new RoundedTransformation(5, 0))
.placeholder(R.drawable.*) //
.error(R.drawable.*) //
.fit() //
.tag(mcontext) //
.into("Your ImageView");

Glide doesn't set GlideDrawable into ImageView after loading image

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.

Loading Same Gallery Image Into Two Different Activity Fragments Android Picasso

Currently I have a Main Activity which has a Fragment loaded into it with a RecyclerView. In the RecyclerView adapter I use Picasso to load in images from the user's gallery based on a stored URI string I have like so:
Picasso.with(context)
.load(imageUri)
.resize(400, 400)
.into(viewHolder.imageView);
When the user clicks on one of these items in the RecyclerView I go to a new Activity and inside its own Fragment onCreateView I load the same image again but size it slightly larger (as the ImageView I'm loading it into is larger size)
Picasso.with(getActivity())
.load(imageUri)
.resize(600, 600)
.centerCrop()
.into(imageView);
My question is...Assuming these images can be quite large...
Is there a better way to load in this image once at say 600px X 600px back when the RecyclerView first needs them, and then reuse the bitmap data in the subsequent Activities and Fragments which need it without reloading again?
I'm open to using a different image loader like Volley if that's better.
Any help would be appreciated.
Marco
You could try Glide it has almost the same api. Instead of Picasso glide has own cache implementation, when Picasso just use http cache and it's hard to control. In glide you need to specify diskCacheStrategy.ALL to make glide cache all you want. Here is cache wiki

Categories

Resources