Here you can find the source of createMaskBitmap(Bitmap src, Resources resource, int mask)
public static Bitmap createMaskBitmap(Bitmap src, Resources resource, int mask)
//package com.java2s; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; public class Main { public static Bitmap createMaskBitmap(Bitmap src, Resources resource, int mask) { Bitmap maskMap = BitmapFactory.decodeResource(resource, mask).copy( Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(maskMap); if (null != src) { canvas.scale(/*from w w w.j av a 2s .c o m*/ (float) maskMap.getWidth() / (float) src.getWidth(), (float) maskMap.getHeight() / (float) src.getHeight()); Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, 0, 0, paint); return maskMap; } return null; } }