Android Common Image Loading library

Source: Internet
Author: User

Android Common Image Loading library

The picture loading involves the image cache, the picture processing, the picture display and so on. The four commonly used picture loading frames are fresco, Imageloader, Picasso, Glide, respectively.

Universal image Loader: Imageloader is the older frame, a powerful picture loading library that contains a wide variety of configurations, the oldest and most widely used.

Imageloader Open Source inventory which features:

1. Multi-threaded download pictures, images can be from the network, file system, project folder assets and drawable medium

2. Support arbitrary configuration imageloader, such as thread pool, picture downloader, memory cache policy, hard disk cache policy, picture display options and some other configuration

3. Memory cache for image support, file system cache or SD card cache

4. Support the image download process monitoring

5. Crop the bitmap based on the size of the control (ImageView), reducing bitmap memory consumption

6. Better control the loading process of the picture, for example, pause the picture loading, restart loading the picture, generally used in the Listview,gridview, the sliding process pauses the Gaga load picture, stops the sliding time to load the picture

7. Provide loading of pictures on slower network

Glide: Google's recommended image loading library, focusing on smooth scrolling.

Glide Open Source Library features:


1. Support Gif, WebP, thumbnail image. Even Video, so it's more like a media cache.

2. Support Priority processing.

3. Memory-friendly, the image default to use the default rgb_565 instead of argb_888, although the clarity is poor, but the picture is smaller, can also be configured to argb_888 ...

Picasso:P Icasso is a very good open-source image loading library produced by Square, which is one of the most popular image loading libraries in Android development now, and with Okhttp to match up!

     Details to use.

Fresco: Facebook, born proud! Not as strong as usual.

     Details to use.

effect (see source code):

Development environment: androidstudio2.2.1+gradle-2.14.1

Introduce dependencies:

// Adapter    Compile ' com.classic.adapter:commonadapter:1.2 '    // Annotated development    compile ' Com.jakewharton : butterknife:7.0.1    ' com.nostra13.universalimageloader:universal-image-loader:1.9.4 '      'com.github.bumptech.glide:glide:3.6.1    ' com.squareup.picasso:picasso:2.5.2 '

Knowledge Involved:

1. Annotated development + (Commonadapter) Universal Adapter use

2. Image loading library: Imageloader, Glide, Picasso

3.webview+swiperefreshlayout implementing loading and refreshing Web pages

Part of the code (Gilde use):

 Public classGildeactivityextendsbaseactivity {/*** The main purpose of Glide is two: * 1. One is to achieve a smooth picture list scrolling effect, * 2. Another is to support remote picture acquisition, sizing and display * 3. Support GIF animation and video stills decoding, smart pause and restart requests, support for shrinking Sketch *http://www.open-open.com/lib/view/open1440397324450.html     */@Bind (R.ID.IMG) ImageView img;    @Bind (R.id.listview) ListView listview; PrivateString Imgurl = "Http://avatar.csdn.net/4/A/A/1_zhh_csdn_ard.jpg"; @Overrideprotected intSetcontentview () {returnr.layout.gilde_img_layout; } @Overrideprotected voidinitlayout () {Glideadapter adapter=NewGlideadapter ( This, R.layout.listview_img_item, Appconfig.resultimgdata ());    Listview.setadapter (adapter); } @OnClick ({r.id.btn0, r.id.btn1, r.id.btn2})voidOnClick (View v) {Switch(V.getid ()) { Caser.id.btn0:test0 ();  Break;  CaseR.id.btn1:test1 ();  Break;  Caser.id.btn2://must be called in the UI threadGlide.get (gildeactivity. This). Clearmemory ();  Break; }    }    //Basic Glide network Picture loading//Glide's with method not only accepts the context, but also accepts activity and Fragment,context automatically obtains from them//image scaling, Centercrop () and Fitcenter ()://use Centercrop to fill the size of the ImageView setting with a picture map, if ImageView's    Private voidtest0 () {Glide.with ( This). Load (Imgurl)//Path Support Png,jpg,gif,mp4. Placeholder (R.mipmap.ic_launcher)//pre-load picture. Error (R.mipmap.ic_launcher)//failed to load picture. Crossfade ()//Fade animation effects. Centercrop (). into (IMG); }    //gif display    Private voidtest1 () {Glide.with ( This). Load ("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&
sec=1491037864865&di=cc8f78a7e5c1d359839cec3463123b47&imgtype=0&
Src=http%3a%2f%2fi.zeze.com%2fattachment%2fforum%2f201501%2f29%2f181236dyjtsu2qinms5qjz.jpg "). Asgif ()//determines whether the loaded URL resource is a GIF-formatted resource. Placeholder (R.mipmap.ic_launcher)//pre-load picture. Error (R.mipmap.ic_launcher)//failed to load picture. Into (IMG);//. Into (New Glidedrawableimageviewtarget (IMG, 1));//if you want to control the number of GIF displays, you can use } //Show Local Video Private voidtest2 () {String FilePath= "/storage/emulated/0/pictures/example_video.mp4"; Glide. With ( This). Load (Uri.fromfile (NewFile (FilePath))) . into (IMG); } //Cache Private voidtest3 () {Glide. with ( This). Load (Imgurl). Skipmemorycache (true)//Skip Memory Cache. Into (IMG); } //Cache Private voidtest4 () {Glide. with ( This). Load (Imgurl). Diskcachestrategy (Diskcachestrategy.none)//Skip hard disk cache. Into (IMG); } /*** Diskcachestrategy.none Don't cache anything * Diskcachestrategy.source only caches original full-resolution images * Diskcachestrategy.result only slow The final image is saved (or converted) * Diskcachestrategy.all caches all versions of the image (default behavior)*///display a circular picture using glide Private voidTest5 () {Glide.with ( This). Load (Imgurl). Asbitmap (). Centercrop (). into (NewBitmapimageviewtarget (img) {@Overrideprotected voidSetresource (Bitmap Resource) {roundedbitmapdrawable circularbitmapdrawable=roundedbitmapdrawablefactory.create (gildeactivity. This. Getresources (), Resource); Circularbitmapdrawable.setcircular (true); Img.setimagedrawable (circularbitmapdrawable); } }); }}

SOURCE Download ...

Android Common Image Loading library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.