Android Bitmap Color Change createMaskBitmap(Bitmap src, Resources resource, int mask)

Here you can find the source of createMaskBitmap(Bitmap src, Resources resource, int mask)

Description

create Mask Bitmap

Declaration

public static Bitmap createMaskBitmap(Bitmap src, Resources resource,
            int mask) 

Method Source Code

//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;
    }
}

Related

  1. setAlpha(Bitmap sourceImg, int number)
  2. tiltShift(Bitmap sentBitmap, int radius, int x, int y)
  3. changeBitmapColor(Bitmap bmp, int color)
  4. toGrayscale(Bitmap bmpOriginal)
  5. toGrayscale(Bitmap bmpOriginal, int pixels)
  6. createTranslucentCompatibleImage(int width, int height)