Example usage for android.graphics ColorMatrix ColorMatrix

List of usage examples for android.graphics ColorMatrix ColorMatrix

Introduction

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

Prototype

public ColorMatrix() 

Source Link

Document

Create a new colormatrix initialized to identity (as if reset() had been called).

Usage

From source file:com.farmerbb.taskbar.service.DashboardService.java

private void addPlaceholder(int cellId) {
    FrameLayout placeholder = (FrameLayout) cells.get(cellId).findViewById(R.id.placeholder);
    SharedPreferences pref = U.getSharedPreferences(this);
    String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null");

    if (!providerName.equals("null")) {
        ImageView imageView = (ImageView) placeholder.findViewById(R.id.placeholder_image);
        ComponentName componentName = ComponentName.unflattenFromString(providerName);

        List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager
                .getInstalledProvidersForProfile(Process.myUserHandle());
        for (AppWidgetProviderInfo info : providerInfoList) {
            if (info.provider.equals(componentName)) {
                Drawable drawable = info.loadPreviewImage(this, -1);
                if (drawable == null)
                    drawable = info.loadIcon(this, -1);

                ColorMatrix matrix = new ColorMatrix();
                matrix.setSaturation(0);

                imageView.setImageDrawable(drawable);
                imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
                break;
            }//from   w  w  w .  ja va2 s  .c om
        }
    }

    placeholder.setVisibility(View.VISIBLE);
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

public Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();/*from ww  w. ja va 2  s.  c o m*/
    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;
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void setBackground(View v, Bitmap bm) {

    if (bm == null) {
        v.setBackgroundResource(0);//from  w w  w  .j  a  va  2s.  co  m
        return;
    }

    int vwidth = v.getWidth();
    int vheight = v.getHeight();
    int bwidth = bm.getWidth();
    int bheight = bm.getHeight();
    float scalex = (float) vwidth / bwidth;
    float scaley = (float) vheight / bheight;
    float scale = Math.max(scalex, scaley) * 1.3f;

    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
    Canvas c = new Canvas(bg);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    ColorMatrix greymatrix = new ColorMatrix();
    greymatrix.setSaturation(0);
    ColorMatrix darkmatrix = new ColorMatrix();
    darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
    greymatrix.postConcat(darkmatrix);
    ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
    paint.setColorFilter(filter);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin
    matrix.postRotate(10);
    matrix.postScale(scale, scale);
    matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center
    c.drawBitmap(bm, matrix, paint);
    v.setBackgroundDrawable(new BitmapDrawable(bg));
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?//from  w w  w .j  ava2s.  co m
 * 
 * @param bitmap
 *            
 * @param saturationValue
 *            
 * @return ??
 */
public static Bitmap saturation(Bitmap bitmap, int saturationValue) {
    // ??
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 
    ColorMatrix saturationColorMatrix = new ColorMatrix();
    // 
    saturationColorMatrix.setSaturation(newSaturationValue);
    // 
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturationColorMatrix));
    // 
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?//  ww w .  j ava2s.com
 * 
 * @param bitmap
 *            
 * @param lumValue
 *            
 * @return ??
 */
public static Bitmap lum(Bitmap bitmap, int lumValue) {
    // ??
    float newlumValue = lumValue * 1.0F / 127;
    // 
    ColorMatrix lumColorMatrix = new ColorMatrix();
    // 
    lumColorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(lumColorMatrix));
    // 
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?/*  w  w  w .java 2 s. co m*/
 * 
 * @param bitmap
 *            
 * @param hueValue
 *            
 * @return ??
 */
public static Bitmap hue(Bitmap bitmap, int hueValue) {
    // ??
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
    // 
    ColorMatrix hueColorMatrix = new ColorMatrix();
    // 
    hueColorMatrix.setRotate(0, newHueValue);
    // 
    hueColorMatrix.setRotate(1, newHueValue);
    // ?
    hueColorMatrix.setRotate(2, newHueValue);
    // 
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(hueColorMatrix));
    // 
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ???/*w w w .jav  a2  s . c o  m*/
 * 
 * @param bitmap
 *            
 * @param lumValue
 *            
 * @param hueValue
 *            
 * @param saturationValue
 *            
 * @return ????
 */
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue, int hueValue, int saturationValue) {
    // ??
    float newSaturationValue = saturationValue * 1.0F / 127;
    // ??
    float newlumValue = lumValue * 1.0F / 127;
    // ??
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;

    // 
    ColorMatrix colorMatrix = new ColorMatrix();

    // 
    colorMatrix.setSaturation(newSaturationValue);
    // 
    colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 
    colorMatrix.setRotate(0, newHueValue);
    // 
    colorMatrix.setRotate(1, newHueValue);
    // ?
    colorMatrix.setRotate(2, newHueValue);

    // 
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    // 
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}

From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

protected Drawable convertToGrayscale(Drawable drawable) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.setSaturation(0);/*from w  ww  . ja v a2  s . c o m*/

    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

    drawable.setColorFilter(filter);

    return drawable;
}

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 {//from   www  .j  ava2s  .  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./*www . jav a  2 s  . 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;
}