Android image library,
Android Image Library
Preface: Image loading involves image caching, image processing, and image display. Four common image loading frameworks: Fresco, ImageLoader, Picasso, and Glide.
Universal Image Loader: ImageLoader is an old framework. It is a powerful image loading library that contains various configurations. It is the oldest and most widely used.
What are the features of ImageLoader Open Source Inventory:
1. multi-threaded download of images. images can be from the network, file system, project folder assets, and drawable Medium
2. Supports random configuration of ImageLoader, such as thread pool, image downloader, memory cache policy, hard disk cache policy, image display options, and other configurations.
3. Supports image memory caching, file system caching, or SD card caching.
4. Supports listening to the image download process.
5. Crop Bitmap based on the size of the control (ImageView) to reduce the memory occupied by Bitmap.
6. it is better to control the image loading process, such as pausing image loading and re-starting image loading. It is generally used in ListView and GridView, and the image loading is paused during sliding, attach an image when stopping the slide
7. Loading images in a slow network
Glide: The image loading library recommended by Google focuses on smooth scrolling.
Glide open source library features:
1. Supports Gif, WebP, and thumbnail. Video, so it should be used as a media cache.
2. priority processing is supported.
3. Memory-friendly. The default RGB_565 is used for images instead of ARGB_888 by default. Although the definition is poor, the images are smaller and can be configured to ARGB_888...
Picasso: Picasso is a very good open-source image loading library produced by Square. It is one of the most popular image loading libraries in Android development. It works better with OkHttp!
Details usage.
Fresco: Facebook, born proud! Not generally powerful.
Details usage.
Effect (see the source code for details ):
Development Environment: AndroidStudio2.2.1 + gradle-2.14.1
Introduce dependency:
// Adapter compile 'com. classic. adapter: commonadapter: 1.2 '// annotation-based compile 'com. jakewharton: butterknife: 7.0.1 'compute' com. nostra13.universalimageloader: universal-image-loader: 1.9.4 'compile 'com. github. bumptech. glide: 3.6.1 'compile 'com. squareup. picasso: 2.5.2'
Knowledge:
1. annotation-based development + (Commonadapter) universal adapter
2. Image Library: ImageLoader, Glide, and Picasso
3. WebView + SwipeRefreshLayout to load and refresh webpages
Part of the Code (used by Gilde ):
Public class GildeActivity extends BaseActivity {/*** Glide has two main purposes: * 1. one is to achieve smooth scrolling of the image list, * 2. the other is to support remote image acquisition, resize, and display * 3. support for Gif animation and video stills decoding, smart pause and restart requests, support for thumbnails * http://www.open-open.com/lib/view/open1440397324450.html */@ Bind (R. id. img) ImageView img; @ Bind (R. id. listview) ListView; private String imgurl = "http://avatar.csdn.net/4/A/A/1_zhh_csdn_ard.jpg"; @ Override protected int setContentV Iew () {return R. layout. gilde_img_layout;} @ Override protected void initLayout () {GlideAdapter adapter = new GlideAdapter (this, R. layout. listview_img_item, AppConfig. resultImgData (); listView. setAdapter (adapter) ;}@ OnClick ({R. id. btn0, R. id. btn1, R. id. btn2}) void onClick (View v) {switch (v. getId () {case R. id. btn0: test0 (); break; case R. id. btn1: test1 (); break; case R. id. btn2: // must be called in the UI thread Glide. get (GildeActivity. this ). clearMemory (); break ;}/// the with method for loading basic glide images // The with method not only accepts Context, but also accepts Activity and Fragment, context will automatically obtain the image scaling from them. centerCrop () and fitCenter (): // use centerCrop to fill the size set by ImageView with the image graph, if the private void test0 () {Glide. with (this ). load (imgurl) // The path supports png, jpg, gif, and mp4. placeholder (R. mipmap. ic_launcher) // preload the image. error (R. mipmap. ic_launcher) // image loading failed. crossFade () // fade in and out animation effect Results. centerCrop (). into (img);} // gif display private void test1 () {Glide. with (this). load ("https://timgsa.baidu.com/timg? Image & quality = 80 & size = b9999_10000 &
Sec = 1491037864865 & di = cc8f78a7e5c1d359839cec4243123b47 & imgtype = 0 &
Failed "). asGif () // determine whether the loaded url resource is a gif resource. placeholder (R. mipmap. ic_launcher) // preload the image. error (R. mipmap. ic_launcher) // image loading failed. into (img );//. into (new GlideDrawableImageViewTarget (img, 1); // to control the number of Gif displays, use} // to display the private void test2 () of the local video () {String filePath = "/storage/emulated/0/Pictures/example_video.mp4"; Glide. with (this ). load (Uri. fromFile (new File (filePath ))). into (img);} // cache private void test3 () {Glide. with (this ). load (imgurl ). skipMemoryCache (true) // skip the memory cache. into (img);} // cache private void test4 () {Glide. with (this ). load (imgurl ). diskCacheStrategy (DiskCacheStrategy. NONE) // skip the hard disk cache. into (img);}/*** DiskCacheStrategy. NONE is not cached * DiskCacheStrategy. SOURCE only caches the original full-resolution image * DiskCacheStrategy. RESULT: only the final image is cached, that is, after the resolution is reduced (or after conversion) * DiskCacheStrategy. ALL cached images of ALL versions (default behavior) * // use Glide to display the circular image private void test5 () {Glide. with (this ). load (imgurl ). asBitmap (). centerCrop (). into (new BitmapImageViewTarget (img) {@ Override protected void setResource (Bitmap resource) {RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory. create (GildeActivity. this. getResources (), resource); circularBitmapDrawable. setCircular (true); img. setImageDrawable (circularBitmapDrawable );}});}}
Download source code...