create A Circular Image - Android Graphics

Android examples for Graphics:Image Crop

Description

create A Circular Image

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;

public class Main {
    public static Bitmap createACircularImage(Bitmap bm) {
        Bitmap circleBitmap = Bitmap.createBitmap(bm.getWidth(),
                bm.getHeight(), Bitmap.Config.ARGB_8888);
        BitmapShader shader = new BitmapShader(bm, Shader.TileMode.CLAMP,
                Shader.TileMode.CLAMP);//from w w  w  . j  av  a 2  s .  c  o m
        Paint paint = new Paint();
        paint.setShader(shader);
        Canvas c = new Canvas(circleBitmap);
        c.drawCircle(bm.getWidth() / 2, bm.getHeight() / 2,
                bm.getWidth() / 2, paint);
        return bm;
    }
}

Related Tutorials