Last active
August 29, 2015 14:17
-
-
Save kayvannj/c71d59a469d1102b7c8f to your computer and use it in GitHub Desktop.
Picasso Transformation for Circle Bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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