Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;

public class Main {
    public static Bitmap getRoundedRectBitmap(Bitmap bitmap) {
        Bitmap result = null;
        Canvas canvas;
        Paint paint;
        try {
            final int width = bitmap.getWidth();
            final int height = bitmap.getHeight();
            result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            canvas = new Canvas(result);
            int color = 0xff424242;
            float radius = width > height ? width / 2 : height / 2;
            paint = new Paint();
            Rect rect = new Rect(0, 0, width, height);
            paint.setAntiAlias(true);
            canvas.drawARGB(0, 0, 0, 0);
            paint.setColor(color);
            canvas.drawCircle(width / 2, height / 2, radius, paint);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
            canvas.drawBitmap(bitmap, rect, rect, paint);
        } catch (NullPointerException | OutOfMemoryError e) {
            e.printStackTrace();
        }
        return result;
    }
}