Example usage for android.graphics ColorMatrix setSaturation

List of usage examples for android.graphics ColorMatrix setSaturation

Introduction

In this page you can find the example usage for android.graphics ColorMatrix setSaturation.

Prototype

public void setSaturation(float sat) 

Source Link

Document

Set the matrix to affect the saturation of colors.

Usage

From source file:com.android.launcher2.AsyncTaskCallback.java

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 {/* w ww.j  a va 2s. c om*/
        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;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Convers a Bitmap to grayscale./* w ww.  j  a  v  a2s . c  o m*/
 * 
 * @param bmpOriginal
 * @return
 */
public static Bitmap media_getGrayScale(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();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}