Skip to content

Instantly share code, notes, and snippets.

@kayvannj
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayvannj/c71d59a469d1102b7c8f to your computer and use it in GitHub Desktop.
Save kayvannj/c71d59a469d1102b7c8f to your computer and use it in GitHub Desktop.
Picasso Transformation for Circle Bitmap
/**
* This is a picasso Transformation that can be used as follows
*
* Picasso.with(mContext)
* .load(someUrl)
* .transform(new CircleTransformation())
* .into(yourImageView);
*
* Credits to https://gist.github.com/aprock/6213395 for most of the code
* /
/**
* Created by kayvan on 3/19/15.
*/
class CircleTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(0, 0, source.getWidth(), source.getHeight() ), source.getWidth(), source.getWidth(), paint);
if (source != output) {
source.recycle();
}
return output;
}
@Override
public String key() {
return "Circular Image";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment