Search in sources :

Example 16 with ColorMatrix

use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.

the class ImageHelper method toGrayscale.

private static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorMatrix cm = new ColorMatrix();
    final Rect rect = new Rect(0, 0, width, height);
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, rect, rect, paint);
    return bmpGrayscale;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 17 with ColorMatrix

use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.

the class ColorHelper method getColorFilter.

public static ColorMatrixColorFilter getColorFilter(int color) {
    float r = Color.red(color) / 255f;
    float g = Color.green(color) / 255f;
    float b = Color.blue(color) / 255f;
    ColorMatrix cm = new ColorMatrix(new float[] { r, 0, 0, 0, 0, 0, g, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, 1, 0 });
    ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
    return cf;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 18 with ColorMatrix

use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.

the class ColorHelper method toGrayscale.

private static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    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;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 19 with ColorMatrix

use of android.graphics.ColorMatrix in project UltimateAndroid by cymcsg.

the class SquareProgressBar method setImageGrayscale.

/**
	 * You can set the image to b/w with this method. Works fine with the
	 * opacity.
	 * 
	 * @param greyscale
	 *            true if the grayscale should be activated.
	 * @since 1.2.0
	 */
public void setImageGrayscale(boolean greyscale) {
    this.greyscale = greyscale;
    if (greyscale) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);
        imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
    } else {
        imageView.setColorFilter(null);
    }
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 20 with ColorMatrix

use of android.graphics.ColorMatrix in project Lightning-Browser by anthonycr.

the class LightningView method setColorMode.

/**
     * Sets the current rendering color of the WebView instance
     * of the current LightningView. The for modes are normal
     * rendering (0), inverted rendering (1), grayscale rendering (2),
     * and inverted grayscale rendering (3)
     *
     * @param mode the integer mode to set as the rendering mode.
     *             see the numbers in documentation above for the
     *             values this method accepts.
     */
private void setColorMode(int mode) {
    mInvertPage = false;
    switch(mode) {
        case 0:
            mPaint.setColorFilter(null);
            // setSoftwareRendering(); // Some devices get segfaults
            // in the WebView with Hardware Acceleration enabled,
            // the only fix is to disable hardware rendering
            setNormalRendering();
            mInvertPage = false;
            break;
        case 1:
            ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(sNegativeColorArray);
            mPaint.setColorFilter(filterInvert);
            setHardwareRendering();
            mInvertPage = true;
            break;
        case 2:
            ColorMatrix cm = new ColorMatrix();
            cm.setSaturation(0);
            ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
            mPaint.setColorFilter(filterGray);
            setHardwareRendering();
            break;
        case 3:
            ColorMatrix matrix = new ColorMatrix();
            matrix.set(sNegativeColorArray);
            ColorMatrix matrixGray = new ColorMatrix();
            matrixGray.setSaturation(0);
            ColorMatrix concat = new ColorMatrix();
            concat.setConcat(matrix, matrixGray);
            ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
            mPaint.setColorFilter(filterInvertGray);
            setHardwareRendering();
            mInvertPage = true;
            break;
        case 4:
            ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter(sIncreaseContrastColorArray);
            mPaint.setColorFilter(IncreaseHighContrast);
            setHardwareRendering();
            break;
    }
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Aggregations

ColorMatrix (android.graphics.ColorMatrix)46 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)46 Paint (android.graphics.Paint)29 Canvas (android.graphics.Canvas)28 Bitmap (android.graphics.Bitmap)27 Resources (android.content.res.Resources)4 BlurMaskFilter (android.graphics.BlurMaskFilter)4 Rect (android.graphics.Rect)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 DisplayMetrics (android.util.DisplayMetrics)4 ImageView (android.widget.ImageView)4 Drawable (android.graphics.drawable.Drawable)3 Matrix (android.graphics.Matrix)2 Path (android.graphics.Path)2 View (android.view.View)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 ShadowView (carbon.shadow.ShadowView)2 ShortcutPickHelper (com.android.settingslib.cm.ShortcutPickHelper)2 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)2 Test (org.junit.Test)2