Back to project page Ocypode.
The source code is released under:
MIT License
If you think the Android project Ocypode listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.ocypode.component.view.imageview; //w ww. j a v a 2 s . c o m import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Shader.TileMode; import android.util.AttributeSet; import android.widget.ImageView; public class CircleImageView extends ImageView { public CircleImageView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setImageBitmap(Bitmap bm) { super.setImageBitmap(createCircleBitmap(bm)); } private Bitmap createCircleBitmap(Bitmap bitmap) { Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); return circleBitmap; } }