Glide Placeholder caching - android

I am just curious if Glide is caching placeholder in the size of image views that request belongs to. I mean, if I have a recycler view and load some image URIs to image view in list items and, say, use a placeholder with size of 512x512 px for each request, will it affect the performance? Or will the placeholder cached in the given size once and then reused every time?

Yes, you are right. Glide will cash only once 512x512 image and use it every time when needed. Comparing to Picasso Glide cashes every resized image, when Picasso resizes on the fly. Glide cashing can also be configured depending on your need using methods like diskCacheStrategy(), onlyRetrieveFromCache() etc. See this link for more information.

Related

Glide taking a long time to load large images from the web into a recyclerview

I'm implementing a RecyclerView with a grid layout where in each grid element there is an ImageView in which Glide should load an image taken from and API.
The API returns images of varying dimensions but mostly lage files, and gives the following information about each image:
width and height
size and format (jpg/png)
original size url
thumbnail size url
The thumbnail is way too low quality to be used.
It allows me to filter for under or above a specific resolution, but if I do that I end up missing on the most interesting images. I want to be able to download a compressed version of any image, can glide do that? Is there a workaround to speed up the loading of such big images?
I tought of allowing better quality of wifi networks but I would like to cover all cases. Thanks.

Picasso Taking time to load images

I'm using picasso to load images in my recycler view adaper but it is taking to much time to load image. Here is my call to load image with picasso.
Picasso.with(hostActivity).load("ImageUrl").fit().centerCrop().into(holder.ImageView);
If I do same thing with asynctask task, image loaded instantly.
Am I doing any thing wrong?
Thanks.
fit() needs to wait for the size of the ImageView to be determined before it can size the image to match, and the size can't be calculated until the end of the layout pass. You might get quicker results by using resize() if you are able to predict reasonable width and height values.
You might also want to look at the Glide library as it takes a different approach to caching that can be quicker than Picasso in some cases, for example instead of caching full size images it caches the resized ones. However, there are many pros and cons to both libraries; although the syntaxes are very similar, some things that work in Picasso will not work in Glide, and vice versa.

Details About Glide Library

I am using the Glide library and wanted to know some more details about it.Does it load the entire picture into the memory,for example if i have a 1920x1080 picture and load it onto a phone with a screen size of 640x480 does it resize and compress or load the whole thing?
Also the thumbnail feature of glide,does it just load a icon version of the image so that it can be used for something like an avatar?
1) Depending on selected diskCacheStrategy Glide saves or original image (1920x1080 in your case) or image processed separately for each of your views (for example with .override(int width, int height) method). The only optimisation which Glide makes for you is storing of image in RGB_565 format instead of system default ARGB_8888.
If you are looking for strategy to reduce trafic as well as memory consumption here is description of model with downloading of images with custom sizes:
backend requirements
android client implementation
2) Thumbnail feature - it is just an option to fill the container view with reduced copy of original image insted of showing empty container or 'progress view' while downloading final image. Here is description of it's rule from Java doc thumbnail(float f):
* Loads a resource in an identical manner to this request except with the dimensions of the target multiplied
* by the given size multiplier. If the thumbnail load completes before the fullsize load, the thumbnail will
* be shown. If the thumbnail load completes afer the fullsize load, the thumbnail will not be shown.
So it is not the proper vay for avatar styling. The usual way instead is combination of override and centerCrop options.

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

Android Volley with Image Caching

Currently I'm working with an application where one activity holds a list view with image and text for each row. I'm downloading the images using the volley. When the list view item is clicked the app will switch to a another activity with a detail view where a large version of the clicked image will show. For the both time I'm using NetworkImageView.
Images are loaded in the list view with caching. But the problem appeared on the detailed view. The images are showing from the previously loaded cache with low resolution. I want to load a good resolution image on detailed view which will cache the image separately for large view.
For the both screen image url are same. How to do that ?
Thanks in advance.
First thing is a bit obvious - make sure you images are at the wanted quality.
If that's the case, you'll probably want to load the image "manually" using the ImageLoader class, as the NetworkImageView by default, optimizes the size of the Bitmap it creates to be the size of the view itself. So what happens is, you first load the thumbnail view which is small, and the saved Bitmap is created in that size instead of the original image size. Then, when the bigger view requests the same image, the cached version is returned which is a small Bitmap, and the view scales it up, creating the low-res appearance.
Try using ImageLoader.get() with the width and height appropriate to the bigger view in the detail screen.
The other alternative is to load 2 versions of the same image.

Categories

Resources