Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;

public class Main {
    /**
     * Returns semi-rounded bitmap. This is used for displaying atn promotion images.
     * 
     * @param context
     * @param input
     * @return
     */
    public static Bitmap getSemiRoundedBitmap(Context context, Bitmap input) {
        Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final float densityMultiplier = context.getResources().getDisplayMetrics().density;
        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, input.getWidth(), input.getHeight());
        final RectF rectF = new RectF(rect);
        //make sure that our rounded corner is scaled appropriately
        final float roundPx = densityMultiplier * 10;
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        //draw rectangles over the corners we want to be square
        canvas.drawRect(input.getWidth() / 2, 0, input.getWidth(), input.getHeight() / 2, paint);
        canvas.drawRect(input.getWidth() / 2, input.getHeight() / 2, input.getWidth(), input.getHeight(), paint);
        paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(input, 0, 0, paint);
        input.recycle();

        return output;
    }
}