Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
        int w = src.getWidth();
        int h = src.getHeight();

        Bitmap bmOut = Bitmap.createBitmap(w, h, src.getConfig());
        int A, R, G, B, pixel;
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                pixel = src.getPixel(x, y);
                A = Color.alpha(pixel);
                R = (int) (Color.red(pixel) * red);
                G = (int) (Color.green(pixel) * green);
                B = (int) (Color.blue(pixel) * blue);
                bmOut.setPixel(x, y, Color.argb(A, R, G, B));
            }
        }
        return bmOut;
    }
}