Search in sources :

Example 41 with ColorMatrix

use of android.graphics.ColorMatrix in project AndroidUtilCode by Blankj.

the class ImageUtils method toGray.

/**
     * 转为灰度图片
     *
     * @param src     源图片
     * @param recycle 是否回收
     * @return 灰度图
     */
public static Bitmap toGray(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src))
        return null;
    Bitmap grayBitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(grayBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(src, 0, 0, paint);
    if (recycle && !src.isRecycled())
        src.recycle();
    return grayBitmap;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 42 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 43 with ColorMatrix

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

the class LockscreenShortcutsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lockscreen_shortcuts);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    mPicker = new ShortcutPickHelper(this, this);
    mShortcutHelper = new LockscreenShortcutsHelper(this, this);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    mFilter = new ColorMatrixColorFilter(cm);
    ImageView unlockButton = (ImageView) findViewById(R.id.middle_button);
    mDefaultTintList = unlockButton.getImageTintList();
    createActionList();
    initiateViews();
    updateDrawables();
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ShortcutPickHelper(com.android.settingslib.cm.ShortcutPickHelper) ColorMatrix(android.graphics.ColorMatrix) ImageView(android.widget.ImageView)

Example 44 with ColorMatrix

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

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 45 with ColorMatrix

use of android.graphics.ColorMatrix in project smartmodule by carozhu.

the class Bitmaputil method toGrayscale.

/**
     * 图片去色,返回灰度图片
     *
     * @param bmpOriginal 传入的图片
     * @return 去色后的图片
     */
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, 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;
}
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)

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