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.content.res.Resources;
import android.graphics.Bitmap;

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

import android.graphics.Canvas;

import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;

public class Main {
    private static Resources _resources;

    /**
     * mask bitmap
     * @param src todo
     * @param mask todo
     * @param dst todo
     * @param dstCanvas todo
     * @param paint todo
     * @param paintMode todo
     * @return todo
     */
    public static Bitmap maskBitmap(Bitmap src, Bitmap mask, Bitmap dst, Canvas dstCanvas, Paint paint,
            PorterDuffXfermode paintMode) {
        if (dst == null)
            dst = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);

        if (dstCanvas == null)
            dstCanvas = new Canvas(dst);

        if (paintMode == null)
            paintMode = new PorterDuffXfermode(Mode.DST_IN);

        if (paint == null) {
            paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint.setXfermode(paintMode);
        }

        dstCanvas.drawBitmap(src, 0, 0, null);
        dstCanvas.drawBitmap(mask, 0, 0, paint);

        paint.setXfermode(null);

        return dst;
    }

    /**
     * mask a bitmap
     *
     * @param src the bitmap to mask
     * @param drawableResId a resource id of the mask
     * @return a bitmap
     */
    public static Bitmap maskBitmap(Bitmap src, int drawableResId) {
        Bitmap mask = BitmapFactory.decodeResource(_resources, drawableResId);

        return maskBitmap(src, mask, null, null, null, null);
    }
}