Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;

import android.graphics.Bitmap.Config;

import android.graphics.BitmapShader;
import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.Shader.TileMode;

public class Main {
    /**
     * create a circle from cutout from a bitmap.
     * does not alter sizes.
     *
     * @param bitmap the bitmap
     * @see #cutCircleFromBitmap(String, int)
     * @return a bitmap circle cutout
     */
    public static Bitmap roundBitMap(Bitmap bitmap) {
        Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

        BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        paint.setShader(shader);

        Canvas c = new Canvas(circleBitmap);

        c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);

        return circleBitmap;
    }
}