Search in sources :

Example 36 with ColorMatrix

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

the class AppsCustomizePagedView method getShortcutPreview.

private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) {
    Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
    final Canvas c = mCachedShortcutPreviewCanvas.get();
    if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) {
        tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
        mCachedShortcutPreviewBitmap.set(tempBitmap);
    } else {
        c.setBitmap(tempBitmap);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
        c.setBitmap(null);
    }
    // Render the icon
    Drawable icon = mIconCache.getFullResIcon(info);
    int paddingTop = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
    int paddingLeft = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
    int paddingRight = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
    int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
    renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
    Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
    c.setBitmap(preview);
    Paint p = mCachedShortcutPreviewPaint.get();
    if (p == null) {
        p = new Paint();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        p.setAlpha((int) (255 * 0.06f));
        //float density = 1f;
        //p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL));
        mCachedShortcutPreviewPaint.set(p);
    }
    c.drawBitmap(tempBitmap, 0, 0, p);
    c.setBitmap(null);
    renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
    return preview;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 37 with ColorMatrix

use of android.graphics.ColorMatrix in project Fairphone by Kwamecorp.

the class AppsCustomizePagedView method getShortcutPreview.

private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) {
    Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
    final Canvas c = mCachedShortcutPreviewCanvas.get();
    if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) {
        tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
        mCachedShortcutPreviewBitmap.set(tempBitmap);
    } else {
        c.setBitmap(tempBitmap);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
        c.setBitmap(null);
    }
    // Render the icon
    Drawable icon = mIconCache.getFullResIcon(info);
    int paddingTop = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
    int paddingLeft = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
    int paddingRight = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
    int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
    renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
    Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
    c.setBitmap(preview);
    Paint p = mCachedShortcutPreviewPaint.get();
    if (p == null) {
        p = new Paint();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        p.setAlpha((int) (255 * 0.06f));
        //float density = 1f;
        //p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL));
        mCachedShortcutPreviewPaint.set(p);
    }
    c.drawBitmap(tempBitmap, 0, 0, p);
    c.setBitmap(null);
    renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
    return preview;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 38 with ColorMatrix

use of android.graphics.ColorMatrix in project glide-transformations by wasabeef.

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

use of android.graphics.ColorMatrix in project ThinkAndroid by white-cat.

the class ImageUtils 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, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    paint.setColorFilter(null);
    c.drawBitmap(bmpGrayscale, 0, 0, paint);
    ColorMatrix cm = new ColorMatrix();
    getValueBlackAndWhite();
    cm.set(carray);
    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 40 with ColorMatrix

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

the class FoldingLayoutActivity method onCreate.

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.folding_drawer_activity_fold);
    mImageView = (ImageView) findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.test));
    if (IS_ISC) {
    //mTextureView = new TextureView(this);
    //mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
    mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view);
    mFoldLayout.setFoldListener(mOnFoldListener);
    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);
    mItemSelectedListener = new ItemSelectedListener();
    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();
    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
    mFoldLayout.setNumberOfFolds(mNumberOfFolds);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

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