Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    public static Bitmap effectWhiten(Bitmap bitmap, int threshold) {
        if (bitmap == null) {
            return bitmap;
        }

        Bitmap dst = bitmap.copy(Bitmap.Config.ARGB_8888, true);

        int height = dst.getHeight();
        int width = dst.getWidth();
        int[] pixels = new int[(width * height)];
        dst.getPixels(pixels, 0, width, 0, 0, width, height);

        for (int YY = 0; YY < width; ++YY) {
            for (int XX = 0; XX < height; ++XX) {
                int bitmapColor = pixels[(YY + XX * width)];
                int[] color = { Color.red(bitmapColor), Color.green(bitmapColor), Color.blue(bitmapColor) };

                if (color[0] > threshold && color[1] > threshold && color[2] > threshold) {
                    color[0] = 255;
                    color[1] = 255;
                    color[2] = 255;
                }
                pixels[(YY + XX * width)] = Color.rgb(color[0], color[1], color[2]);
            }
        }

        dst.setPixels(pixels, 0, width, 0, 0, width, height);
        return dst;
    }
}