Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glide rounded corner transform issue

Tags:

android

i use the following code to load an image with rounded corners into imageview using glide:

Glide.with(this)
                .load(url)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }
                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        return false;
                    }
                })
                .transition(withCrossFade())
                .apply(new RequestOptions().transform(new RoundedCorners(50)).error(R.drawable.default_person).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE))
                .into(mBinding.profileImgv);

enter image description here images get pixelized for some reason. Can somebody tell me where is the problem?

like image 403
tsiro Avatar asked Jul 19 '17 09:07

tsiro


People also ask

How do you make a round picture on Glide?

circleCrop() . into(imageView); Glide V3: You can use RoundedBitmapDrawable for circular images with Glide.


3 Answers

I had the same issue, the problem in my case was the image what i've tried to load had less size in pixels (320x480), then the ImageView size in pixels. My solution was the following:

My ImageView in the xml file:

    <ImageView
    android:id="@+id/image_program_thumb"
    android:layout_width="match_parent"
    android:layout_height="186dp" />

ProgramViewHolder.java class

@BindView(R.id.image_program_thumb) ImageView mProgramThumbnail;
.....
void bindData(final Program item) {
    RequestOptions requestOptions = new RequestOptions();
    requestOptions = requestOptions.transforms(new CenterCrop(), new RoundedCorners(16));
    Glide.with(itemView.getContext())
            .load(item.getImage())
            .apply(requestOptions)
            .into(mProgramThumbnail);
....

}

P.S. I use 4.2.0 version of Glide

like image 144
Mondok Tamas Avatar answered Oct 16 '22 11:10

Mondok Tamas


in Glide V4

Try like this

 Glide.with(this.context)
                .load(url)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(14)))
                .into(ImageView);
like image 34
Savad Avatar answered Oct 16 '22 09:10

Savad


For Glide v4.9 transformation (java):

Glide.with(this)
            .load(R.drawable.sample)
            .transform(new CenterCrop(),new RoundedCorners(25))
            .into(image);
like image 43
Samad Talukder Avatar answered Oct 16 '22 11:10

Samad Talukder