Android Glide get pictures of path and glide get pictures bitmap

Source: Internet
Author: User

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

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.