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.Canvas;

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

public class Main {
    public static Bitmap toSepia(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 grMatrix = new ColorMatrix();
        grMatrix.setSaturation(0);

        ColorMatrix scMatrix = new ColorMatrix();
        scMatrix.setScale(1f, .85f, .72f, 1.0f);
        grMatrix.setConcat(scMatrix, grMatrix);

        ColorMatrixColorFilter f = new ColorMatrixColorFilter(grMatrix);
        paint.setColorFilter(f);
        c.drawBitmap(bmpOriginal, 0, 0, paint);
        return bmpGrayscale;
    }
}