change Bitmap Contrast Brightness - Android Graphics

Android examples for Graphics:Bitmap Effect

Description

change Bitmap Contrast Brightness

Demo Code


//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 changeBitmapContrastBrightness(Bitmap bmp,
            float contrast, float brightness) {
        ColorMatrix cm = new ColorMatrix(new float[] { contrast, 0, 0, 0,
                brightness, 0, contrast, 0, 0, brightness, 0, 0, contrast,
                0, brightness, 0, 0, 0, 1, 0 });

        Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(),
                bmp.getConfig());/*from  www . j a va  2 s .  c om*/

        Canvas canvas = new Canvas(ret);

        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        canvas.drawBitmap(bmp, 0, 0, paint);

        return ret;
    }
}

Related Tutorials