get Alpha Bitmap - Android Graphics

Android examples for Graphics:Bitmap Color

Description

get Alpha Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Bitmap.Config;

import android.graphics.Canvas;

import android.graphics.Paint;

public class Main {

    public static Bitmap getAlphaBitmap(Bitmap mBitmap, int color) {

        Bitmap mAlphaBitmap = Bitmap.createBitmap(mBitmap.getWidth(),
                mBitmap.getHeight(), Config.ARGB_8888);

        Canvas mCanvas = new Canvas(mAlphaBitmap);
        Paint mPaint = new Paint();
        mPaint.setColor(color);/*w  w  w  .  j ava 2 s . c  o  m*/
        Bitmap alphaBitmap = mBitmap.extractAlpha();
        mCanvas.drawBitmap(alphaBitmap, 0, 0, mPaint);

        return mAlphaBitmap;
    }
}

Related Tutorials