Example usage for android.graphics ColorMatrix setSaturation

List of usage examples for android.graphics ColorMatrix setSaturation

Introduction

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

Prototype

public void setSaturation(float sat) 

Source Link

Document

Set the matrix to affect the saturation of colors.

Usage

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();// w  ww .ja  v a 2 s.  c o m
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
    d.setColorFilter(cf);

}

From source file:Main.java

public static Bitmap toGreyBitmap(Bitmap bitmap) {
    Bitmap grey = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(grey);
    Paint p = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    p.setColorFilter(new ColorMatrixColorFilter(cm));
    c.drawBitmap(bitmap, 0, 0, p);//w  w  w.j  a v  a  2  s  .c o m
    return grey;
}

From source file:Main.java

public static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();/*w  ww .  ja  v  a 2 s.c  o  m*/
    width = bmpOriginal.getWidth();
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}

From source file:Main.java

public static Bitmap setGrayscale(Bitmap source) {
    int width, height;
    height = source.getHeight();/*from   ww w  .ja  v  a2  s  .c om*/
    width = source.getWidth();
    Bitmap bmpGrayScale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayScale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(source, 0, 0, paint);
    return bmpGrayScale;
}

From source file:Main.java

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;
}

From source file:Main.java

public static Bitmap convertGrayscale(final Bitmap source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0f);
    paint.setColorFilter(new ColorMatrixColorFilter(matrix));
    canvas.drawBitmap(source, 0, 0, paint);
    return output;
}

From source file:Main.java

public static Bitmap getSaturationBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(faceIconGreyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return faceIconGreyBitmap;
}

From source file:Main.java

public static final Bitmap grey(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap greyBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(greyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return greyBitmap;
}

From source file:Main.java

/**
 * Method to remove color in a Bitmap, creating a gray scale image.
 *
 * @param bmpOriginal The original Bitmap.
 * @return The gray scale Bitmap./*w w w  .  jav a2 s  . c om*/
 */
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
    Bitmap bmpGrayscale = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(),
            Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(bmpOriginal, 0, 0, paint);

    return bmpGrayscale;
}

From source file:Main.java

public static final Bitmap grey(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(faceIconGreyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return faceIconGreyBitmap;
}