Katedral Pillon Katedral Pillon - 4 months ago 21x
Android Question

android: create circular image with picasso

The question had been asked and there had been a promise made for the very version of Picasso that I am using: How do I send a circular bitmap to an ImageView using Picasso? I am very new to Picasso and only thing I have used so far is

Picasso.with(context).load(url).resize(w, h).into(imageview);

I have already found https://gist.github.com/julianshen/5829333 but I am not sure how to combine it with the line above in a non-ackward way.


Research a bit before as there are answers avaiable.Anyhow, follow This Link and read it carefully to know how to use it-

try this---

import com.squareup.picasso.Transformation;

public class CircleTransform implements Transformation {
    public Bitmap transform(Bitmap source) {
        int size = Math.min(source.getWidth(), source.getHeight());

        int x = (source.getWidth() - size) / 2;
        int y = (source.getHeight() - size) / 2;

        Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
        if (squaredBitmap != source) {

        Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint();
        BitmapShader shader = new BitmapShader(squaredBitmap,
                BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);

        float r = size / 2f;
        canvas.drawCircle(r, r, r, paint);

        return bitmap;

    public String key() {
        return "circle";

then simply apply it like---

Picasso.with(activity).load(mayorShipImageLink).transform(new CircleTransform()).into(ImageView);