Android's use of glide (Gaussian blur, load monitor, fillet picture) _android

Source: Internet
Author: User
Tags int size set time

Gaussian blur, load monitor, fillet picture These believe that everyone is familiar with, how to achieve these effects, please refer to this article to learn.

1, reference

Compile ' com.github.bumptech.glide:glide:3.7.0 '

2, loading pictures

2.1 Basic Load

Glide.with (context)
. Load (URL)
. into (ImageView);

2.2 Setting loading and loading failures

Glide.with (context)
 . Load (URL)
 . Placeholder (r.drawable.loading)//placeholder is a picture in the load, you can put a GIF
 . Error ( r.drawable.failed)//Failed picture
 . into (view);

2.3 Loading animations only

Glide.with (context)
. Load (URL)
. Asgif ()//can only load GIF files
. into (ImageView); 

2.4 Add a picture fade effect

Glide.with (context).
 load (URL)
 . Placeholder (r.drawable.loading).
 error (r.drawable.failed) 
 . Crossfade (1000)//Can be set time length, default "300ms"
 . into (view);

2.5 Load Gaussian blur diagram

Glide.with (context).
 load (URL)
 . Placeholder (r.drawable.loading).
 error (r.drawable.failed) 
 . Crossfade (1000)
 . Bitmaptransform (New Blurtransformation (context,23,4))//"23": Set ambiguity (between 0.0 and 25.0), default "25"; 4 ": Picture scaling ratio, default" 1 ".
 . into (view);

2.6 Load Listener Requestlistener

Glide.with (this). Load (InternetURL). Listener (New requestlistener<string, glidedrawable> () {
   @Override Public
   Boolean onexception (Exception E, String model, Target<glidedrawable> Target, Boolean Isfirstresource) {
    Toast.maketext (Getapplicationcontext (), "Resource load Exception", Toast.length_short). Show ();
    return false;
   }
   This is used to monitor whether the picture is loaded
   @Override public
   boolean Onresourceready (glidedrawable resource, String model, target< Glidedrawable> Target, Boolean Isfrommemorycache, Boolean isfirstresource) {
    Toast.maketext ( Getapplicationcontext (), "Picture loading Complete", Toast.length_short. Show ();
    return false;
   }
  }). Into (ImageView);


Note: If you want to set the picture transparency to 0 after the load completes, you cannot set the. Placeholder (r.drawable.url), otherwise you will not be able to achieve the desired effect.

2.7 Image caching mechanism

Glide caching Policy

Glide the disk cache and memory cache are turned on by default, and of course you can set a specific caching policy for a single picture.
Set picture not added to memory cache

Glide.with.
 load (eatfoodyimages[0])
 . Skipmemorycache (True)
 . into (imageviewinternet);


Set pictures not to be added to the disk cache

Glide.with.
 load (eatfoodyimages[0])
 . Diskcachestrategy (Diskcachestrategy.none). into
 ( Imageviewinternet);

Glide supports multiple disk caching policies:

Diskcachestrategy.none: Do not cache pictures
Diskcachestrategy.source: Caching Picture source files
Diskcachestrategy.result: Cached Modified picture
Diskcachestrategy.all: Caching All the pictures, default

2.8 Load Fillet Picture

The public class Glidecircletransform the extends Bitmaptransformation {public Glidecircletransform (context) {super (
 context); @Override protected Bitmap transform (Bitmappool pool, Bitmap totransform, int outwidth, int outheight) {return Cir
 Clecrop (pool, totransform);
  private static Bitmap Circlecrop (Bitmappool pool, Bitmap source) {if (Source = null) return null;
  int size = Math.min (Source.getwidth (), Source.getheight ());
  int x = (Source.getwidth ()-size)/2;
  int y = (source.getheight ()-size)/2;
  TODO this could is acquired from the pool too Bitmap squared = Bitmap.createbitmap (source, x, y, size, size);
  Bitmap result = pool.get (size, size, Bitmap.Config.ARGB_8888);
  if (result = = null) {result = Bitmap.createbitmap (size, size, Bitmap.Config.ARGB_8888);
  } Canvas Canvas = new Canvas (result);
  Paint Paint = new Paint ();
  Paint.setshader (New Bitmapshader (squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); Paint.setaNtialias (TRUE);
  float r = size/2f;
  Canvas.drawcircle (R, R, R, paint);
 return result;
 @Override public String getId () {return getclass (). GetName ();

 }
}

Use:

Glide.with (mcontext).
 load (IMAGEURL).
 Transform (new Glidecircletransform (Mcontext)). into
 ( Holder.imageview);

3, reference

Http://www.jb51.net/article/98570.htm

Http://www.jb51.net/article/98570.htm

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.