Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;

import android.graphics.Paint;

import java.util.List;

public class Main {
    public static Bitmap getNewCombinedByPiecesAlsoGrayscaled(List<Bitmap> bitmapList, int currentStage,
            int numStages) {
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(colorMatrixColorFilter);

        //i mean, don't use greyscale, but add here all the functionalities to reuse the canvas
        int originalTotalWidth = bitmapList.get(0).getWidth() * numStages;
        Bitmap finalBitmap = Bitmap.createBitmap(originalTotalWidth, bitmapList.get(0).getHeight(),
                Bitmap.Config.ARGB_8888);
        float delta = 0f;
        Canvas comboImage = new Canvas(finalBitmap);
        for (int i = 0; i < numStages; i++) {
            comboImage.translate(delta, 0f);
            if (i > currentStage) {
                comboImage.drawBitmap(bitmapList.get(i), 0f, 0f, paint);
            } else {
                comboImage.drawBitmap(bitmapList.get(i), 0f, 0f, null);
            }
            delta = originalTotalWidth / numStages;
        }
        return finalBitmap;
    }
}