Today, the main research glide get the picture path, bitmap usage, I believe it also bothered everyone for a long time, I have been looking for a long time on the internet, basically did not, later studied the next, also refer to the next API document, summed up the following several ways:
1. Get bitmap:
1) After the image download cache is good to get
Glide.with (Mcontext). Load (URL). Asbitmap (). into (new simpletarget<bitmap>() { @Override Public void Onresourceready (Bitmap resource, glideanimation<? Super bitmap> glideanimation) { Image.setimagebitmap (Resource); } // you can set the callback type by setting Asbitmap in the
The above is a simple method, the following is a comprehensive approach, can be perfectly controlled:
Glide.with (Mcontext). Load (URL). Asbitmap (). into (NewTarget<bitmap>() {@Override Public voidonloadstarted (drawable placeholder) {} @Override
Public voidonloadfailed (Exception E, drawable errordrawable) {} @Override Public voidOnresourceready (Bitmap resource, glideanimation<? Super Bitmap>glideanimation) { //TODO Set Bitmap} @Override Public voidonloadcleared (drawable placeholder) {} @Override Public voidGetSize (Sizereadycallback cb) {} @Override Public voidsetrequest (Request request) {} @Override PublicRequest getrequest () {return NULL; } @Override Public voidOnStart () {} @Override Public voidonStop () {} @Override Public voidOnDestroy () {}});
2) Get via URL
Bitmap Mybitmap = glide.with (applicationcontext) . Load (yoururl) // must . Centercrop () . into (in). Get ()
2. Get the picture cache path
futuretarget<file> future =Glide.with (mcontext). Load ("URL"). Downloadonly ( -, -); Try{File Cachefile= future.Get(); String Path=Cachefile.getabsolutepath (); } Catch(interruptedexception e) {e.printstacktrace (); } Catch(executionexception e) {e.printstacktrace (); }
Note: This code needs to be executed in the thread, otherwise it will be saved.
Android Glide get pictures of path and glide get pictures bitmap