Android – use Picasso with roundedbitmapdrawable
I read the udacity lecture on material design and mentioned using roundedbitmapdrawable to realize circular view. But I have some trouble making it work with Picasso
I'm not sure how Picasso works, but there are large non square images in the file storage. Therefore, I use Picasso as follows:
Picasso.with(context).load(f).resize(densityDpi, densityDpi).centerInside().transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
Log.d("jano", "transformation running");
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), source);
drawable.setCircular(true);
drawable.setCornerRadius(source.getWidth() / 2.0f);
return drawable.getBitmap();
}
@Override
public String key() {
return "circle";
}
}).into(imageView);
However, the image is square without rounded corners. This is what I want to achieve
Is there any simple way to do this using roundedbitmapdrawable, or must the conversion be fully implemented? (I saw it on stackoverflow)
Please don't submit the answer without explanation. Why can't you use it? I just want to know the combination of these two projects (Picasso, rounded bitmapdrawable)
resolvent:
I tried a lot to do the same thing, but it didn't work... I think this was a problem during getbitmap. Anyway, I solved this problem: (please note that the main difference is that I use SETIMAGE as a paintable object instead of converting to bitmap as I said)
Picasso.with(getContext())
.load(mUser.user.profileImageUrl)
.into(mProfileImage, new Callback() {
@Override
public void onSuccess() {
Bitmap source = ((BitmapDrawable) mProfileImage.getDrawable()).getBitmap();
RoundedBitmapDrawable drawable =
RoundedBitmapDrawableFactory.create(getContext().getResources(), source);
drawable.setCircular(true);
drawable.setCornerRadius(Math.max(source.getWidth() / 2.0f, source.getHeight() / 2.0f));
mProfileImage.setImageDrawable(drawable);
}
@Override
public void one rror() {
}
});