create Circle Image - Android Graphics

Android examples for Graphics:Image Shape

Description

create Circle Image

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;

public class Main {

    public static Bitmap createCircleImage(Bitmap source, int min) {
        final Paint paint = new Paint();
        paint.setAntiAlias(true);//from www . j  av  a 2  s .  c o  m
        Bitmap target = Bitmap.createBitmap(min, min,
                Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(target);

        canvas.drawCircle(min / 2, min / 2, min / 2, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        canvas.drawBitmap(source, 0, 0, paint);
        return target;
    }

    public static Bitmap createCircleImage(String source, int min) {
        Bitmap bitmap = BitmapFactory.decodeFile(source);
        return createCircleImage(bitmap, min);
    }
}

Related Tutorials