clip Round Corner Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

clip Round Corner Bitmap

Demo Code

import android.content.Context;
import android.graphics.*;
import android.net.Uri;

public class Main{

    public static Bitmap clipRoundCornerBitmap(Bitmap bitmap, float f, int i) {
        Bitmap bitmap1;//  w ww.  j a  va  2s.  c  o m
        if (bitmap == null) {
            bitmap1 = null;
        } else {
            bitmap1 = Bitmap.createBitmap(bitmap.getWidth(),
                    bitmap.getHeight(),
                    android.graphics.Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap1);
            Paint paint = new Paint();
            Rect rect = new Rect(0, 0, bitmap.getWidth(),
                    bitmap.getHeight());
            RectF rectf = new RectF(rect);
            paint.setColor(i);
            paint.setFlags(7);
            canvas.drawARGB(0, 0, 0, 0);
            canvas.drawRoundRect(rectf, f, f, paint);
            paint.setXfermode(new PorterDuffXfermode(
                    android.graphics.PorterDuff.Mode.SRC_IN));
            canvas.drawBitmap(bitmap, rect, rect, paint);
        }
        return bitmap1;
    }

}

Related Tutorials