Search in sources :

Example 31 with ColorMatrix

use of android.graphics.ColorMatrix in project kickmaterial by byoutline.

the class LUtils method toGrayscale.

public static void toGrayscale(ImageView iv) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    iv.setColorFilter(filter);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 32 with ColorMatrix

use of android.graphics.ColorMatrix in project Carbon by ZieIony.

the class AnimUtils method brightnessSaturationFadeOut.

public static ValueAnimator brightnessSaturationFadeOut(final ImageView imageView, Animator.AnimatorListener listener) {
    final ValueAnimator animator = ValueAnimator.ofFloat(1, 0);
    final AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
    animator.setInterpolator(interpolator);
    animator.setDuration(800);
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        ColorMatrix saturationMatrix = new ColorMatrix();

        ColorMatrix brightnessMatrix = new ColorMatrix();

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float fraction = animator.getAnimatedFraction();
            saturationMatrix.setSaturation((Float) animator.getAnimatedValue());
            float scale = 2 - interpolator.getInterpolation(Math.min((1 - fraction) * 4 / 3, 1));
            brightnessMatrix.setScale(scale, scale, scale, interpolator.getInterpolation(Math.min((1 - fraction) * 2, 1)));
            saturationMatrix.preConcat(brightnessMatrix);
            imageView.setColorFilter(new ColorMatrixColorFilter(saturationMatrix));
            if (imageView.getParent() != null)
                ((View) imageView.getParent()).postInvalidate();
        }
    });
    animator.start();
    return animator;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ColorMatrix(android.graphics.ColorMatrix) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) ShadowView(carbon.shadow.ShadowView)

Example 33 with ColorMatrix

use of android.graphics.ColorMatrix in project Shuttle by timusus.

the class GrayscaleTransformation method transform.

@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int width = source.getWidth();
    int height = source.getHeight();
    Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(width, height, config);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    Canvas canvas = new Canvas(bitmap);
    ColorMatrix saturation = new ColorMatrix();
    saturation.setSaturation(0f);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturation));
    canvas.drawBitmap(source, 0, 0, paint);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}
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 34 with ColorMatrix

use of android.graphics.ColorMatrix in project picasso by square.

the class GrayscaleTransformation method transform.

@Override
public Bitmap transform(Bitmap source) {
    Bitmap result = createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
    Bitmap noise;
    try {
        noise = picasso.load(R.drawable.noise).get();
    } catch (IOException e) {
        throw new RuntimeException("Failed to apply transformation! Missing resource.");
    }
    BitmapShader shader = new BitmapShader(noise, REPEAT, REPEAT);
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
    Paint paint = new Paint(ANTI_ALIAS_FLAG);
    paint.setColorFilter(filter);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(source, 0, 0, paint);
    paint.setColorFilter(null);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
    canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
    source.recycle();
    noise.recycle();
    return result;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap.createBitmap(android.graphics.Bitmap.createBitmap) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) IOException(java.io.IOException) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader)

Example 35 with ColorMatrix

use of android.graphics.ColorMatrix in project android_packages_apps_Launcher2 by CyanogenMod.

the class Utilities method initStatics.

private static void initStatics(Context context) {
    final Resources resources = context.getResources();
    final DisplayMetrics metrics = resources.getDisplayMetrics();
    final float density = metrics.density;
    sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
    sIconTextureWidth = sIconTextureHeight = sIconWidth;
    sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
    sGlowColorPressedPaint.setColor(0xffffc300);
    sGlowColorFocusedPaint.setColor(0xffff8e00);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.2f);
    sDisabledPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    sDisabledPaint.setAlpha(0x88);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix) BlurMaskFilter(android.graphics.BlurMaskFilter) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

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