change ImageView Brightness - Android User Interface

Android examples for User Interface:ImageView

Description

change ImageView Brightness

Demo Code


//package com.java2s;

import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;

import android.widget.ImageView;

public class Main {

    public static void changeBrightness(ImageView imageview,
            float brightness) {
        imageview/*from w  w w  .  j a v a2s  . co m*/
                .setColorFilter(getBrightnessMatrixColorFilter(brightness));
    }

    public static void changeBrightness(Drawable drawable, float brightness) {
        drawable.setColorFilter(getBrightnessMatrixColorFilter(brightness));
    }

    private static ColorMatrixColorFilter getBrightnessMatrixColorFilter(
            float brightness) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1, 0, 0,
                brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });
        return new ColorMatrixColorFilter(matrix);
    }
}

Related Tutorials