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.Path;

import android.util.Log;
import android.view.View;

public class Main {
    private static String TAG = "COS_UTILS_IMAGES";

    public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        Path path = new Path();
        path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)),
                Path.Direction.CCW);

        Canvas canvas = new Canvas(outputBitmap);
        canvas.clipPath(path);
        canvas.drawBitmap(bitmap, 0, 0, null);
        return outputBitmap;
    }

    public static Bitmap CreateBitmap(View v) {
        if (v == null) {
            Log.e(TAG, "View is null. Cannot create bitmap");
            return null;
        }

        v.setDrawingCacheEnabled(true);
        v.buildDrawingCache();

        Bitmap bitmap = null;
        try {
            bitmap = Bitmap.createBitmap(v.getDrawingCache());
        } catch (Exception e) {
            Log.e(TAG, "Unable to create bitmap");
        }

        v.destroyDrawingCache();
        v.setDrawingCacheEnabled(false);

        return bitmap;
    }
}