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.Bitmap.Config;

import android.graphics.Canvas;

import android.graphics.Paint;

public class Main {
    private static final Paint paint_comm = new Paint(Paint.ANTI_ALIAS_FLAG);

    public static final Bitmap complementedBitmapByAlpha(Bitmap bitmap) {
        if (null == bitmap) {
            return null;
        }

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        if (width == height) {
            return bitmap;
        }

        int len = width > height ? width : height;
        Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setAlpha(0);
        canvas.drawPaint(paint);

        if (width > height) {
            int devide = (width - height) / 2;
            canvas.drawBitmap(bitmap, 0, devide, paint_comm);
        } else {
            int devide = (height - width) / 2;
            canvas.drawBitmap(bitmap, devide, 0, paint_comm);
        }
        return output;
    }
}