Load ListView of bitmap efficiently and responsively - android

I have looked at Glide and understand that Glide doesn't take Bitmap (or a Future of Bitmap) parameter in load function.
My current approach is to fall back to manual way following the blog here. Multithreading For Performance, just replacing the download function to create the bitmap in real time.
I wonder is there any image libraries could handle this task? Thanks.
UPDATE:
Or I can actually save the Bitmap in advanced then only pass the file name to Glide. it loads the image the normal way. In this situation, I need to house-keep the cache file.

Related

difference between Drawee and ImagePipeline in Fresco Image Loading Library

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.

Download image as thumbnail in listview adapter android

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.

Android image view makes app slow

In my app I have a list view, which contains an image view. The image is loaded from bas64 encoded string. First the string is decoded and then converted it to bitmap and then the bitmap is loaded to the image view.
All the decoding is done in an async task and concurrency is handled according to the below documentation.
Processing Bitmaps Off the UI Thread
The problem is the app is scrolling slow, and all other async tasks are not executing after that.
any possible solutions?
You probably insterting a huge Bitmap into a tiny ImageView like assume the image is FHD 1920x1280 and your ImageView is 192x128. You should load a smaller or same size Bitmap into ImageView. I guess this is a reason of scroll lags. Also it could be that your layout is too complex and should be optimized.
As for
async tasks are not executing after that
nobody can tell you anything without seeing your code.
If you are getting image URL from server you can store if you want to in local DB. Don't store base64 in database just store the image URL's.But for image loading you can simply use libraries that are available like Glide or Picasso for image loading. Your list view is lagging as you are doing heavy operation like decoding base64 and loading that bitmap. Just give it a try, it will work. You can load image using single line code like
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
you might need to put images into a folder "drawable-nodpi", since normaly android app will try to resize large image first, then load it, then show show the original image(by resize again), this process will cost much CPU which make your app respond slow. So just create a "drawable-nodpi" folder as the "drawable" folder, cut/paste all large images in the new folder

Load bitmap lazy, just before it is seen

I've a Listview with images. I am using an adapter to display the images because i get just a URL from a web service. At the moment i load all images Async, that works but its very inefficient. I get 100-200 images / URLs and mostly i do not need all.
I am looking for a solution to load a bitmap just before it is seen.
for example:
Bitmap 1 (i see it on the screen -> load bitmap)
Bitmap 2 (i see it on the screen -> load bitmap)
Bitmap 3 (i don't see it on the screen but its the next one -> load bitmap)
Bitmap 4 (i don't see it, nothing to do)
Bitmap 5 (i don't see it, nothing to do)
How can I do this?
You should implement the Holder pattern for your listview. See the documentation here
I use Universal Image Loader library, and lazy loading works perfect, take a look at it here:
Universal Image Loader at Github

Save custom bitmap into UniversalImage Loader

Im using Universal Image Loader and works well in my app, however i need get the app icons and shorcuts bitmaps, And As far that i know can't get this using UIL, so i use package manager or other resource to load the bitmaps, so my problem is if ican use any option to "push" into UIL the bitmap and then "pull" this bitmap if its available i can use
MemoryCacheUtil.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache());
Whith this code i can get the cached bitmap but its possible "save" the image using UIL?

Categories

Resources