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;

public class Main {

    public static Bitmap setContrast(Bitmap srcBitmap, float contrast) {
        Bitmap bitmap = Bitmap.createBitmap(srcBitmap);
        ColorMatrix cm = new ColorMatrix(
                new float[] { contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 });
        cm.setSaturation(contrast);
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(srcBitmap, 0, 0, paint);
        return bitmap;
    }

    public static Bitmap setSaturation(Bitmap srcBitmap, float sat) {
        Bitmap bitmap = Bitmap.createBitmap(srcBitmap);
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(sat);
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(srcBitmap, 0, 0, paint);
        return bitmap;
    }
}