How to round an image with Glide library?

前端 未结 22 1776
悲哀的现实
悲哀的现实 2020-11-28 00:46

So, anybody know how to display an image with rounded corners with Glide? I am loading an image with Glide, but I don\'t know how to pass rounded params to this library.

22条回答
  •  醉梦人生
    2020-11-28 01:01

    I found one easy and simple solution for add border over imageview in which color want to set or add gradient over image.

    STEPS:

    1. Take one frame layout and add two images.You can set size as per your requirement. For imgPlaceHolder , you need one white image or color which you want to set.

            
    
            
        
    
    1. After placing this code on xml file , put below line in java file.

      Glide.with(this).load(R.drawable.image01).asBitmap().centerCrop().into(new BitmapImageViewTarget(imgPic) {
          @Override
          protected void setResource(Bitmap resource) {
              RoundedBitmapDrawable circularBitmapDrawable =
                      RoundedBitmapDrawableFactory.create(getResources(), resource);
              circularBitmapDrawable.setCircular(true);
              imageView.setImageDrawable(circularBitmapDrawable);
          }
      });
      
      Glide.with(this).load(R.drawable.white_bg).asBitmap().centerCrop().into(new BitmapImageViewTarget(imgPlaceHolder) {
          @Override
          protected void setResource(Bitmap resource) {
              RoundedBitmapDrawable circularBitmapDrawable =
                      RoundedBitmapDrawableFactory.create(getResources(), resource);
              circularBitmapDrawable.setCircular(true);
              imgTemp2.setImageDrawable(circularBitmapDrawable);
          }
      });
      

    This will make border of imageview simply with out any extra padding and margin.

    NOTE : White image is compulsory for border otherwise it will not work.

    Happy codding :)

提交回复
热议问题