Example usage for android.graphics ColorMatrix ColorMatrix

List of usage examples for android.graphics ColorMatrix ColorMatrix

Introduction

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

Prototype

public ColorMatrix() 

Source Link

Document

Create a new colormatrix initialized to identity (as if reset() had been called).

Usage

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

/**
* ?// ww  w.  j a v a  2s .c o  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:com.ifoer.util.NetPOSPrinter.java

public Bitmap bitmapDuiBi(Bitmap bp) {
    ColorMatrix cm = new ColorMatrix();
    Bitmap bmp = Bitmap.createBitmap(bp.getWidth(), bp.getHeight(), Config.ARGB_8888);
    cm.set(new float[] { 2.0f, 0.0f, 0.0f, 0.0f, 50.0f, 0.0f, 2.0f, 0.0f, 0.0f, 50.0f, 0.0f, 0.0f, 2.0f, 0.0f,
            50.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f });
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    new Canvas(bmp).drawBitmap(bp, 0.0f, 0.0f, paint);
    return bmp;/*from  w w  w.j ava  2s  .  co m*/
}

From source file:com.pixelpixel.pyp.MainActivity.java

public void onResume() {
    super.onResume();

    if (chosenEffect > 0) {
        effectMatrix = new ColorMatrix();
        switch (chosenEffect) {
        case 1: {
            applyOriginal();/*from   w w w.j a v  a  2  s . c  o  m*/
            break;
        }
        case 2: {
            effectMatrix.setSaturation(0);
            applyEffect();
            break;
        }
        case 3: {
            effectMatrix.set(sepMat);
            applyEffect();
            break;
        }
        case 4: {
            effectMatrix.set(invert);
            applyEffect();
            break;
        }
        case 5: {
            effectMatrix.set(dark);
            applyEffect();
            break;
        }
        case 6: {
            effectMatrix.set(sweetDreams);
            applyEffect();
            break;
        }
        case 7: {
            effectMatrix.set(vivid);
            applyEffect();
            break;
        }
        default:
            break;
        }
        //After setting the effect, we reset the variable.
        chosenEffect = 0;

    }
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static void converToGrayscale(Drawable drawable) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);/* w  w w . j  a  va 2s.  co  m*/

    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

    drawable.setColorFilter(filter);

}

From source file:com.aimfire.gallery.cardboard.PhotoActivity.java

public Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();//from w w  w . j a  v  a2  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);
    bmpOriginal.recycle();
    return bmpGrayscale;
}

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

/**
 * ??Drawable??.//  w  w w  .ja  v a2s.  c  om
 *
 * @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:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java

public Bitmap toGrayscale(Bitmap bmpOriginal) {
    int height = bmpOriginal.getHeight();
    int 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);/*from  w w  w  .  java2s.  com*/

    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}

From source file:com.derrick.movies.MovieDetailsActivity.java

private ColorMatrix geColorMatrix() {
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(2);/*w w  w  . j  a va2  s  .  co  m*/
    ColorMatrix colorScale = new ColorMatrix();
    colorScale.setScale(1, 1, 0.8f, 1);
    colorMatrix.postConcat(colorScale);

    return colorMatrix;

}

From source file:image_cache.ImageWorker.java

public void toGrayscale(String buildFBFriendImageUrl, ImageView imageView) {
    if (buildFBFriendImageUrl == null) {
        return;/*w ww .ja  v  a2  s.  co  m*/
    }

    Bitmap bmpOriginal = null;

    if (mImageCache != null) {
        bmpOriginal = mImageCache.getBitmapFromMemCache(String.valueOf(buildFBFriendImageUrl));
    }

    if (bmpOriginal != null) {
        // Bitmap found in memory cache
        imageView.setImageBitmap(bmpOriginal);
        imageView.setBackgroundColor(0);
    } else if (cancelPotentialWork(buildFBFriendImageUrl, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been
        // pulled from the
        // framework and slightly modified. Refer to the docs at the top of
        // the class
        // for more info on what was changed.
        task.executeOnExecutor(ImageTask.DUAL_THREAD_EXECUTOR, buildFBFriendImageUrl);
    }
    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);
    imageView.setImageBitmap(bmpGrayscale);

}

From source file:com.example.hudpassthrough.BluetoothChat.java

private Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();//from  www . ja v a2s .  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;
}