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.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;

import android.graphics.RectF;

import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    public static Bitmap getRoundedCornerBitmap3(Drawable imageDrawable, int radius) {

        Bitmap d = ((BitmapDrawable) imageDrawable).getBitmap();
        BitmapShader shader = new BitmapShader(d, TileMode.CLAMP, TileMode.CLAMP);

        int size = Math.min(d.getWidth(), d.getHeight());
        Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        RectF outerRect = new RectF(0, 0, size, size);
        //      float cornerRadius = radius;

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setShader(shader);
        paint.setAntiAlias(true);
        paint.setColor(Color.RED);
        canvas.drawCircle(outerRect.centerX(), outerRect.centerY(), d.getWidth() / 2, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        imageDrawable.setBounds(0, 0, size, size);

        Canvas canvas1 = new Canvas(output);

        RectF outerRect1 = new RectF(0, 0, size, size);

        Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint1.setShader(shader);
        paint1.setAntiAlias(true);
        paint1.setColor(Color.RED);
        canvas1.drawCircle(outerRect1.centerX(), outerRect1.centerY(), d.getWidth() / 2, paint);

        paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        return output;
    }
}