Brief introduction
At the Google Developer Forum in Thailand, Google introduced a picture loading library called Glide, the author of Bumptech. The library is widely used in Google's open source projects, including the official app released at the 2014 Google I/O conference.
Characteristics
(1) Easy to use
(2) high degree of adaptability and high adaptive degree
(3) Support Common image format: Jpg png gif WEBP
(4) Support a variety of data sources: network, local, resources, Assets, etc.
(5) Efficient cache policy: support memory and disk image cache, the default bitmap format with rgb_565, the use of at least half of RAM.
(6) Lifecycle Integration: Automatic management of requests based on activity/fragment life cycle
(7) Efficient processing bitmap: Use bitmap pool to make bitmap reuse, actively call recycle Reclaim bitmap that need to be recycled, reduce system recovery pressure.
Feature API Description: 1) Simple to use:
Glide .with(this) .load("http://xxx.com/source/a.png") .into(imageView);
2) use of Glide.with ()
(1) with (context context). With the application context, glide requests are not controlled by the activity/fragment lifecycle.
(2) with (activity activity). Using activity as the context, glide requests are subject to activity lifecycle control.
(3) with (fragmentactivity activity). Glide requests are subject to fragmentactivity lifecycle control.
(4) with (Android.app.Fragment Fragment). Glide requests are subject to fragment lifecycle control.
(5) with (Android.support.v4.app.Fragment Fragment). Glide requests are subject to fragment lifecycle control.
3) Use of load ()
Glide basically can load any media resources that can be obtained
- SD Card resources:
Load ("file://" + environment.getexternalstoragedirectory (). GetPath () + "/test.jpg")
- Assets Resources:
Load ("File:///android_asset/3.gif")
- Raw resources:
Load ("Android.resource://com.frank.glide/raw/raw_1") or Load ("android.resource://com.frank.glide/raw/" +R.raw.raw_ 1)
- Drawable Resources:
Load ("Android.resource://com.veyron.glide/drawable/news") or Load ("android.resource://comveyron.glide/drawable/" + R.drawable.news)
- ContentProvider Resources:
Load ("content://media/external/images/media/139469")
- HTTP resources:
Load ("Http://img.my.csdn.NET/uploads/201508/05/1438760757_3588.jpg")
- HTTPS Resources:
Load ("HTTPS://IMG.ALICDN.COM/TPS/TB1UYHOMPXXXXCLXVXXXXXXXXXX-476-538.JPG_240X5000Q50.JPG_.WEBP")
In addition, load is not limited to string types:
load(Uri uri),loadfile),load(Integer resourceId),load(URL url),load(byte[] model),load
4) Important functions
(1) Disable the memory cache:. Skipmemorycache (true)(2) Clear the memory cache://must be called in the UI threadGlide.get (context). Clearmemory (); (3Disable the disk cache:. Diskcachestrategy (Diskcachestrategy.none) (4) to clear the disk cache://must be called in a background thread, it is recommended to Clearmemory ()Glide.get (ApplicationContext). Cleardiskcache (); (5) Gets the cache size:NewGetdiskcachesizetask (TextView). Execute (NewFile (Getcachedir (), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)), class Getdiskcachesizetask extends asynctask< File, Long, long> {Private FinalTextView Resultview; Public Getdiskcachesizetask(TextView Resultview) { This. Resultview = Resultview;}@Overrideprotected void OnPreExecute() {Resultview.settext ("Calculating ...");}@Overrideprotected void onprogressupdate(Long ... values) {/* OnPostExecute (values[values.length-1]); */}@OverrideprotectedLongDoinbackground(File ... dirs) {Try{LongTotalSize =0; for(File dir:dirs) {publishprogress (totalsize); TotalSize + = Calculatesize (dir); }returnTotalSize; }Catch(RuntimeException ex) {FinalString message = String.Format ("Cannot get size of%s:%s", Arrays.tostring (dirs), ex);NewHandler (Looper.getmainlooper ()). Post (NewRunnable () {@Override Public void Run() {Resultview.settext ("Error"); Toast.maketext (Resultview.getcontext (), message, Toast.length_long). Show (); } }); }return 0L;}@Overrideprotected void OnPostExecute(Long size) {String Sizetext = android.text.format.Formatter.formatFileSize (Resultview.getcontext (), size); Resultview.settext (Sizetext);}Private Static Long calculatesize(File dir) {if(dir = =NULL)return 0;if(!dir.isdirectory ())returnDir.length ();Longresult =0; File[] Children = dir.listfiles ();if(Children! =NULL) for(File child:children) result + = Calculatesize (child);returnResult;}} (6Specifies the priority load order for the resource://Priority loadingGlide. With (context), load (Heroimageurl). Priority (Priority.high). to (Imageviewhero);//post-loadGlide. With (context), load (Itemimageurl). Priority (Priority.low). into (Imageviewitem); (7The thumbnail is displayed first, and then the original image is displayed://Use 1/10 of the original image as a thumbnailGlide. With ( This). Load ("Http://inthecheesefactory.com/uploads/source/nestedfragment/fragments.png"). Thumbnail (0.1f). into (IV_0);//Use other images as thumbnailsDrawablerequestbuilder<integer> thumbnailrequest = Glide. With ( This). Load (r.drawable.news); Glide.with ( This). Load ("Http://inthecheesefactory.com/uploads/source/nestedfragment/fragments.png"). Thumbnail (thumbnailrequest). into (IV_0); (8) to the picture to cut, blur, filter and other processing: specific to see the demo source
5) Some API introduction:
Add:
CenterCrop()fitCenter() 也是裁剪技术,即缩放图像让图像都测量出来等于或小于 ImageView 的边界范围。该图像将会完全显示,但可能不会填满整个 ImageView。
Steps to use:
1) Add dependencies in Build.gradle:
‘com.github.bumptech.glide:glide:3.7.0‘
2) If your project does not have a support-v4 library, you also need to add support-v4 dependencies:
‘com.android.support:support-v4:23.3.0‘
3) If you are using transformations, you can add a custom transform library
Add Dependencies:
‘jp.wasabeef:glide-transformations:2.0.1‘ Iftouse‘jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0‘
DemoExampleforglide
Glide of "Android advanced" picture loading frame