Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; public class Main { public static Bitmap multiply(Bitmap bitmap1, Bitmap bitmap2) { double alpha = 0.1; int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); int resultValue = (int) (Math.abs((value2 / 255.0) * (value1 / 255.0)) * 255); // resultValue = (resultValue>255/2)?255:0; result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); } // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; } public static Bitmap toGrayScale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; } }