Glide加载圆角图片

直接上代码

public class MainActivity extends AppCompatActivity {
   //控件地址https://github.com/hdodenhof/CircleImageView
   CircleImageView circleImageView;
   ImageView imageView;
   private String url = "http://img5.poco.cn/mypoco/myphoto/20080508/07/43519158200805080713083441715619253_001.jpg";


   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       imageView = (ImageView) findViewById(R.id.image);
       circleImageView = (CircleImageView) findViewById(R.id.profile_image);
       Glide.with(this)
               .load(url)
               .error(R.drawable.error)
               .placeholder(R.drawable.default_dog)
               .into(imageView);

 /*      //方案一:不用动画( .dontAnimate())
       Glide.with(this)
               .load(url)
               .error(R.drawable.error)
               .placeholder(R.drawable.default_dog)
               .dontAnimate()
               .into(circleImageView);
*/
/*

       //方案二 :不适用占位符
       Glide.with(this)
               .load(url)
               .error(R.drawable.error)
               .centerCrop()
               .into(circleImageView);
*/
      //方案三 :控件是ImageView或者CircleImageView
       Glide.with(this)
               .load(url)
               .asBitmap()
               .centerCrop()
               .error(R.drawable.error)
               .placeholder(R.drawable.default_dog)
               .into(new BitmapImageViewTarget(imageView){
                   @Override
                   public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                       RoundedBitmapDrawable circularBitmapDrawable =
                               RoundedBitmapDrawableFactory.create(imageView.getResources(), resource);
                       circularBitmapDrawable.setCircular(true);
                       imageView.setImageDrawable(circularBitmapDrawable);
                   }
               });

/*        //方案四 :控件是CircleImageView
       Glide.with(this)
               .load(url)
               .asBitmap()
               .centerCrop()
               .error(R.drawable.error)
               .placeholder(R.drawable.default_dog)
               .into(new BitmapImageViewTarget(circleImageView) {
                   @Override
                   public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                       circleImageView.setImageBitmap(resource);
                   }
               });*/
 /*      //方案五: 重写BitmapTransformation,控件是ImageView ,参考https://github.com/wasabeef/glide-transformations
       Glide.with(this)
               .load(url)
               .error(R.drawable.error)
               .placeholder(R.drawable.default_dog)
               .bitmapTransform(new CropCircleTransformation(this))
               .into(imageView);*/
   }
}

你可能感兴趣的:(Glide加载圆角图片)