androidandroid-glide

How to round an image with Glide library?


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.

I need display image like following example:

enter image description here


Solution

  • Glide V4:

        Glide.with(context)
            .load(url)
            .circleCrop()
            .into(imageView);
    

    Glide V3:

    You can use RoundedBitmapDrawable for circular images with Glide. No custom ImageView is required.

     Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                imageView.setImageDrawable(circularBitmapDrawable);
            }
        });