This is also the most recent project used in the third-party picture loading framework, here also summed up, a simple introduction to some of the ways to use.
UIL Picture Loading frame features
Introduction:
- Project Address: Https://github.com/nostra13/Android-Universal-Image-Loader
- Loading images asynchronously or loading a large number of images often encounters problems such as picture confusion or oom. UIL image caching, which currently uses the widest range of image caches, supports most features of the mainstream picture cache.
Let's take a look at the three-level caching principle that the picture loads
Features:
1.多线程下载图片,图片可以来源于网络,文件系统,项目文件夹assets中以及drawable中等 2.支持随意的配置ImageLoader,例如线程池,图片下载器,内存缓存策略,硬盘缓存策略,图片显示选项以及其他的一些配置 3.支持图片的内存缓存,文件系统缓存或者SD卡缓存 4.支持图片下载过程的监听 5.根据控件(ImageView)的大小对Bitmap进行裁剪,减少Bitmap占用过多的内存 6.较好的控制图片的加载过程,例如暂停图片加载,重新开始加载图片,一般使用在ListView,GridView中,滑动过程中暂停加载图片,停止滑动的时候去加载图片 7.提供在较慢的网络下对图片进行加载
- Of course, the mainstream picture loading there are a few other
- Picasso
- Cube Imageloader
- Fresco This can take a look at my other article (Fresco Picture loading framework for a brief introduction)
- Glide
UIL Picture Loading frame use explanationFirst step, Project introduction
Imageloader jar package introduced in the project: https://github.com/nostra13/Android-Universal-Image-Loader/raw/master/downloads/ Universal-image-loader-1.9.5.jar
Or to download this project, and then import into the project, using the library relies on the way to reference, if you do not know how to import the demo and library dependencies, you can look at the
Androidstudio importing local and GitHub projects, and how to add a third-party dependency introduction
Step Two
配置ImageLoder参数(ImageLoaderConfiguration) ImageLoaderConfiguration configuration = ImageLoaderConfiguration .createDefault(this);
Step Three
初始化ImageLoader ImageLoader.getInstance()
Fourth Step
displayImage(), loadImage(),loadImageSync()
OK, let's start loading the pictures.
At this time, we need to configure Imageloader parameters, that is, in the application configuration, here our application using a singleton mode:
Public class myapplication extends application{ Private StaticMyApplication instance=NULL;@Override Public void onCreate() {Super. OnCreate (); This. instance= This; Initimageloader (Getapplicationcontext ()); } Public StaticMyApplicationgetinstance(){returnInstance }Private void Initimageloader(Context context) {File Cachedir = storageutils.getcachedirectory (context); Imageloaderconfiguration configuration =NewImageloaderconfiguration. Builder (context). ThreadPoolSize (5)//thread pool. DiskCache (NewUnlimiteddiskcache (Cachedir))//Memory card. threadpriority (Thread.norm_priority-2)//Thread Priority. Denycacheimagemultiplesizesinmemory (). MemoryCache (NewLargestlimitedmemorycache (2*1024x768*1024x768))//Memory Cache. Memorycachesize (2*1024x768*1024x768)//Memory Cache size. Diskcachesize ( -*1024x768*1024x768)//memory card cache size. Diskcachefilecount ( -)//Memory card file Count. Memorycachesizepercentage ( -)//Default. Diskcachefilenamegenerator (NewHashcodefilenamegenerator ())//Default. Imagedownloader (NewBaseimagedownloader ( This,5* +, -* +))//Default. Defaultdisplayimageoptions (Displayimageoptions.createsimple ())//Default //.writedebuglogs (). Tasksprocessingorder (Queueprocessingtype.fifo)//FIFO. build (); Imageloader.getinstance (). init (configuration); }}
Next, we are going to get an example of Imageloader, and set displayimageoptions parameters, here I enclose a displayimageoptions configuration diagram:
Mimageloader = Imageloader. getinstance();Moptions = new Displayimageoptions. Builder(). showimageonloading(R. Mipmap. IC_launcher)//The default diagram displayed when the picture is loaded. Showimageforemptyuri(R. Mipmap. IC_launcher)//Picture is displayed when the address is empty. Showimageonfail(R. Mipmap. IC_launcher)//Picture loading fails when displayed. Cacheondisk(TRUE)//settings are saved in SDcard. Cacheinmemory(TRUE)//settings are stored in memory. Build();
Finally we're going to load the picture:
Before loading:
After loading successfully:
is not very simple, and the configuration is easy to understand, but unfortunately, this framework has stopped the update, but I believe that such a good open source framework, there will be a lot of people remember. Of course, my project is loaded with pictures, and there's no other great way to do it, like
Load image, decode it to Bitmap and display BitmapinchImageView (or any other view//which implements Imageaware interface) Imageloader.displayimage (Imageuri, ImageView, Optio NS, new Imageloadinglistener () {@Override public void onloadingstarted (String imageuri, view view) {//Start loading...} @Override public void onloadingfailed (String imageuri, view view, Failreason Failreason) {//load failed...} @Override public void Onloadingcomplete (String imageuri, view view, Bitmap loadedimage) {//loading complete...} @Override public void onloadingcancelled (String imageuri, view view) {//load Cancel...}}, new Imageloadingprogresslistener () {@Override public void onprogressupdate (String imageuri, view view, int Curr ENT, int total) {//load percentage...}});
//Load image, decode it to Bitmap and Return Bitmap to callback ImageSize targetsize = new ImageSize (80 , 50 ); //result Bitmap'll be fit to this size imageloader.loadimage (Imageuri, Targetsize, Options, new Simpleimageloadinglistener () {@ Override public void onloadingcomplete (String imageuri, view view, Bitmap loadedimage) {/ /do whatever-want with Bitmap }});
toandreturnnew ImageSize(8050to this sizeBitmap bmp = imageLoader.loadImageSync(imageUri, targetSize, options);
Well, want to know more about Universal-image-loader, you can go to the official website to download and study slowly, here is not much to explain the ha.
Universal-image-loader (UIL) Picture loading framework using a simple introduction