Example usage for android.graphics ColorMatrixColorFilter ColorMatrixColorFilter

List of usage examples for android.graphics ColorMatrixColorFilter ColorMatrixColorFilter

Introduction

In this page you can find the example usage for android.graphics ColorMatrixColorFilter ColorMatrixColorFilter.

Prototype

public ColorMatrixColorFilter(@NonNull float[] array) 

Source Link

Document

Create a color filter that transforms colors through a 4x5 color matrix.

Usage

From source file:Main.java

public static void changeDefaultViewPressState(View view, float[] press) {
    if (view.getBackground() == null) {

    } else {/*from  ww  w  .j av  a 2 s . c  o  m*/
        view.getBackground().setColorFilter(new ColorMatrixColorFilter(press));
        view.setBackgroundDrawable(view.getBackground());
    }

}

From source file:Main.java

public static ColorMatrixColorFilter createRGBColorFilter(int aRed, int aGreen, int aBlue) {
    final float[] array = new float[] { 0, 0, 0, 0, aRed, 0, 0, 0, 0, aGreen, 0, 0, 0, 0, aBlue, 0, 0, 0, 1,
            0 };/*from www.  j  a  v  a 2s . co  m*/
    return new ColorMatrixColorFilter(array);
}

From source file:Main.java

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 });/*  w ww  .  ja v a2  s. c  om*/
    return new ColorMatrixColorFilter(matrix);
}

From source file:Main.java

public static ColorMatrixColorFilter brightIt(int fb) {
    ColorMatrix cmB = new ColorMatrix();
    cmB.set(new float[] { 1, 0, 0, 0, fb, 0, 1, 0, 0, fb, 0, 0, 1, 0, fb, 0, 0, 0, 1, 0 });

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(cmB);//from  ww  w  .ja v a2s  . c o  m
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(colorMatrix);
    return f;
}

From source file:Main.java

public static void changeBrightness(ImageView imageview, 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 });//from w  w  w  . j a  va 2s.c o m
    imageview.setColorFilter(new ColorMatrixColorFilter(matrix));
}

From source file:Main.java

public static void doGray(Drawable d) {
    //Make this drawable mutable.     
    //A mutable drawable is guaranteed to not share its state with any other drawable.     
    d.mutate();/*from  w ww . j a  v a2 s.  c  o m*/
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
    d.setColorFilter(cf);

}

From source file:Main.java

/**
 * /*w  w w .ja va 2s .  c  o m*/
 * @param paint
 */
public static void invertCanvasColors(Paint paint) {
    float mx[] = { -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
            1.0f, 1.0f, 1.0f, 1.0f, 0.0f };
    ColorMatrix cm = new ColorMatrix(mx);
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
}

From source file:Main.java

public static void toColorScale(ImageView imageView) {
    float[] colorMatrix = { 0.33f, 0.33f, 0.33f, 0, 100 - 255, //red
            0.33f, 0.33f, 0.33f, 0, 100 - 255, //green
            0.33f, 0.33f, 0.33f, 0, 100 - 255, //blue
            0, 0, 0, 1, 0 //alpha
    };/*from  ww w. j a  va2s  . c o  m*/

    ColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    imageView.setColorFilter(colorFilter);
}

From source file:Main.java

public static ColorMatrixColorFilter createDarkerColorFilter(float aDarkRatio) {
    final float[] array = new float[] { aDarkRatio, 0, 0, 0, 0, 0, aDarkRatio, 0, 0, 0, 0, 0, aDarkRatio, 0, 0,
            0, 0, 0, 1, 0 };//from   w w  w.j a v a  2  s  . com
    return new ColorMatrixColorFilter(array);
}

From source file:Main.java

public static Paint getPaintFromColor(int color) {
    final float[] array = new float[20];
    array[18] = 1;/*from  ww  w. j ava  2 s. c  om*/
    array[1] = (float) Color.red(color) / 255;
    array[6] = (float) Color.green(color) / 255;
    array[11] = (float) Color.blue(color) / 255;
    final Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(array));
    return paint;
}