Search in sources :

Example 21 with ColorMatrix

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

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

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

the class Bitmaputil method returnContrastBitmap.

/**
     * 改变bitmap 对比度
     *
     * @param bitmap
     * @param progress
     * @return
     */
public static Bitmap returnContrastBitmap(Bitmap bitmap, int progress) {
    //曝光度
    Bitmap contrast_bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    // int brightness = progress - 127;
    float contrast = (float) ((progress + 64) / 128.0);
    ColorMatrix contrast_cMatrix = new ColorMatrix();
    contrast_cMatrix.set(new float[] { contrast, 0, 0, 0, 0, 0, // 改变对比度
    contrast, // 改变对比度
    0, // 改变对比度
    0, // 改变对比度
    0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 });
    Paint contrast_paint = new Paint();
    contrast_paint.setColorFilter(new ColorMatrixColorFilter(contrast_cMatrix));
    Canvas contrast_canvas = new Canvas(contrast_bmp);
    // 在Canvas上绘制一个已经存在的Bitmap。这样,dstBitmap就和srcBitmap一摸一样了
    contrast_canvas.drawBitmap(bitmap, 0, 0, contrast_paint);
    return contrast_bmp;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 23 with ColorMatrix

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

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

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

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

use of android.graphics.ColorMatrix in project 9GAG by Mixiaoxiao.

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 / but never used in the example application
 */
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)

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