circular Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

circular Bitmap

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Canvas;

import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;

public class Main {

    public static Bitmap circular(Bitmap bitmap, int revise) {
        int width = bitmap.getWidth() + revise;
        int height = bitmap.getHeight() + revise;

        Bitmap output = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(output);

        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, width, height);
        final RectF rectF = new RectF(rect);

        paint.setAntiAlias(true);//from www. j  a v  a  2 s .  c om
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawOval(rectF, paint);


        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }
}

Related Tutorials