I am using Fresco Image Loader in my application in which uri is loaded into SimpleDraweeView. I have a list of images, sometimes i load the same image into two different views. In this case does fresco loads the image from cache into SimpleDraweeView or does it downloads the image from the network whenever needed and also where exactly do i need to use Drawee and ImagePipeline. Please help me.
Fresco library is built specifically to address concerns like this. To answer your first question, no, the image won't be downloaded twice. It won't even be decoded twice. Fresco avoids doing any duplicate work. You should be completely fine in using the same uri in multiple views at the same time.
As for your other question, Drawee operates on an API level above ImagePipeline. Those two are not competing. ImagePipeline is to Drawee as a Wheel is to a Car. If you want to display the image you should be using Drawee and not ImagePipeline. If you need to get the actual image bytes or to do something else with the Bitmap other than displaying it, you should use the ImagePipeline.
Related
I have a recyclerview that I want to display images that I have saved in drawables in jpeg. For loading I was using an Async Task, but this doesn't preload or Cache them. I was told to use one of the tools like fresco or glide to do that, but which one can do the Job better?
The most important thing for me is that the app doesn't crash, but it would also be nice to be able to preload certain images already before the View is displayed and afterwards preload as many as memory allows.
You can use Fresco for this. An example for a recycler view that loads images from the network can be found here:
https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/drawee/DraweeRecyclerViewFragment.java
I am trying to load images (around 5mb each) into ImageView's of size 45x45 dp in a RecyclerView. Even though original image is large, doesn't Glide load a smaller version of it because target ImageView is small? So, I expect Glide to load images in just a few seconds with an average internet speed. But, it takes like 20 seconds. What is the problem?
Images are stored in firebase storage.
Glide code :
Glide.with(context).load(firebaseStorageUrl).into(imageView);
Glide needs to load the full image from the internet before it can resize it. So the download takes a long time the first time. Afterwards it can use the small image from the cahe it created if you have caching activated.
In case you don't want to load smaller files, I recommend using a Gif-drawable library for loading large images from Glide into GifDrawable(works as an ImageView).
It can load files more than 100MB very fast. It works with plain JPG, PNG and BMP too. If these are GIFs, it plays without any delay or freeze.
If drawables declared by android:src and/or android:background are GIF files then they will be automatically recognized as GifDrawables and animated. If given drawable is not a GIF then mentioned Views work like plain ImageView and ImageButton.
Glide downloads the image first, and then you have methods to retrieve the image as bitmap to resize and compress the image. However, that won't solve your problem . Possibly there are two solutions for this:
Keep a low sized image in the server.
Use a File downloader library, which helps to download images serially and asynchronously as a queue, which would help to download the file quick. FileDownloader library is a good option for this.
Use Override in Glide for load image faster.
I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).
I have a decent android app which is using two fragments one of them is Listfragment. And my question is, can I use Asynctask to download the image and compress it to a thumbnail and then assign it to an imageview ? (Imagine there are like 100 items in ListView). Or is this even possible to call the asynctask each time ?
You don't need to reinvent the wheel. There are libraries which already can download, cache and resize image for you. For instance Picasso:
Picasso
.with(context)
.load(url)
.resizeDimen(width, height)
.centerCrop()
.error(R.drawable.error_img);
.into(placeholder);
For this task, I would strongly recommend the use of an external library.
There are many to choose from that can be used to download, display and cache images from an online source. As many of these libraries have been developed for many years, they are usually going to be better than any bespoke code you write.
I've a ListView in which each row item contains many ImageViews apart from some content.
That is, there will be many list items, each containing many images.
In order to not to hold user unnecessarily, I'm showing the content first & then downloading the images asynchronously.
Currently, for each image I'm starting a new AsycTask.
Although, it working alright, but this not a good approach.
In place of this, what should I use?
use this library, best in android for image loading..
https://github.com/nostra13/Android-Universal-Image-Loader
Your scenario seems to fit exactly to use LazyLoading of images. This basically loads images in the background and shows them as soon as they're loaded.
You might want to see this:
Lazy load of images in ListView
An alternative would be using a ThreadPoolExecutor with the images to load, but the above works pretty well and is recommended.
Try using the library
http://square.github.io/picasso/
Many common pitfalls of image loading on Android are handled automatically by Picasso:
Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.