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 Bitmap handleImageEffect(Bitmap bm, float hue, float saturation, float lum) {
    Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();

    ColorMatrix hueMatrix = new ColorMatrix();
    hueMatrix.setRotate(0, hue);// ww w. j a v a  2 s  .  c  o m
    hueMatrix.setRotate(1, hue);
    hueMatrix.setRotate(2, hue);

    ColorMatrix saturationMatrix = new ColorMatrix();
    saturationMatrix.setSaturation(saturation);

    ColorMatrix lumMatrix = new ColorMatrix();
    lumMatrix.setScale(lum, lum, lum, 1);

    ColorMatrix imageMatrix = new ColorMatrix();
    imageMatrix.postConcat(hueMatrix);
    imageMatrix.postConcat(saturationMatrix);
    imageMatrix.postConcat(lumMatrix);

    paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
    canvas.drawBitmap(bm, 0, 0, paint);
    return bmp;
}

From source file:Main.java

public static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();/*from   w  ww .  java2  s .c om*/
    width = bmpOriginal.getWidth();

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    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:com.byoutline.kickmaterial.utils.LUtils.java

public static void toGrayscale(ImageView iv) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);

    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    iv.setColorFilter(filter);/*from   ww w.  j a v a  2s .  c  om*/
}

From source file:Main.java

static public void setImageColor(ImageView view, Bitmap sourceBitmap, int rgbcolor)// ,Bitmap sourceBitmap)
{
    if (sourceBitmap != null) {
        float R = Color.red(rgbcolor);
        float G = Color.green(rgbcolor);
        float B = Color.blue(rgbcolor);

        Log.v("R:G:B", R + ":" + G + ":" + B); //

        float[] colorTransform = { R / 255f, 0, 0, 0, 0, // R color
                0, G / 255f, 0, 0, 0 // G color
                , 0, 0, B / 255f, 0, 0 // B color
                , 0, 0, 0, 1f, 0f };/*  w  w  w. j a  va2s  .com*/

        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0f); // Remove Colour

        colorMatrix.set(colorTransform);
        ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);

        Bitmap mutableBitmap = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true);
        view.setImageBitmap(mutableBitmap);
        Canvas canvas = new Canvas(mutableBitmap);
        canvas.drawBitmap(mutableBitmap, 0, 0, paint);

    }
}

From source file:Main.java

private static Paint getGrayScalePaint() {
    Paint paint = new Paint();
    paint.setAntiAlias(true);// ww w . j  av a 2s  .  c o  m
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(colorMatrixColorFilter);
    return paint;
}

From source file:Main.java

public static Bitmap setContrast(Bitmap srcBitmap, float contrast) {
    Bitmap bitmap = Bitmap.createBitmap(srcBitmap);
    ColorMatrix cm = new ColorMatrix(
            new float[] { contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 });
    cm.setSaturation(contrast);
    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:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static void converToGrayscale(Drawable drawable) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);

    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

    drawable.setColorFilter(filter);/*w  w w . j  a  v  a  2 s .  c om*/

}

From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java

/**
 * ??Drawable??.//from  w  ww  .  j a  va  2 s .co m
 *
 * @param drawable ??Drawable
 * @return ??Drawable
 */
public static Drawable convertToGrayScale(final Drawable drawable) {
    Drawable clone = drawable.getConstantState().newDrawable().mutate();
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0.2f);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    clone.setColorFilter(filter);
    return clone;
}

From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java

/**
* ?//from   w ww  . j  av  a  2s  . co m
* @param bmpOriginal
* @return
*/
public static Bitmap toGrayscale(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 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:jahirfiquitiva.iconshowcase.adapters.LaunchersAdapter.java

private ColorFilter bnwFilter() {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);
    return new ColorMatrixColorFilter(matrix);
}