blend Bitmap Image - Android Graphics

Android examples for Graphics:Bitmap Combine

Description

blend Bitmap Image

Demo Code


//package com.java2s;

import java.util.ArrayList;
import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.Xfermode;

import android.util.Log;

public class Main {
    public static Bitmap blend(Bitmap src, Bitmap dst, int width,
            int height, Xfermode mode) {
        ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
        bitmaps.add(src);// w  w w . ja  va2  s.com
        bitmaps.add(dst);
        return blend(bitmaps, width, height, mode);
    }

    public static Bitmap blend(ArrayList<Bitmap> bitmaps, int width,
            int height, Xfermode mode) {
        Bitmap blendedBitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        Canvas myCanvas = new Canvas(blendedBitmap);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        // paint.setXfermode(mode);
        final int length = bitmaps.size();
        for (int i = 0; i < length; i++) {
            if (i > 0) {
                paint.setXfermode(mode);
            }
            myCanvas.drawBitmap(bitmaps.get(i), 0, 0, paint);
        }
        return blendedBitmap;
    }
}

Related Tutorials