Example usage for android.graphics ColorMatrix set

List of usage examples for android.graphics ColorMatrix set

Introduction

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

Prototype

public void set(float[] src) 

Source Link

Document

Assign the array of floats into this matrix, copying all of its values.

Usage

From source file:Main.java

public static void setContrastTranslateOnly(ColorMatrix cm, float contrast) {
    float scale = contrast + 1.f;
    float translate = (-.5f * scale + .5f) * 255.f;
    cm.set(new float[] { 1, 0, 0, 0, translate, 0, 1, 0, 0, translate, 0, 0, 1, 0, translate, 0, 0, 0, 1, 0 });
}

From source file:Main.java

@SuppressWarnings("deprecation")
private static Drawable getSelectedDrawable(BitmapDrawable mDrawable) {
    Bitmap srcBitmap = mDrawable.getBitmap();
    Bitmap bmp = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Config.ARGB_8888);
    ColorMatrix cMatrix = new ColorMatrix();
    cMatrix.set(new float[] { 1, 0, 0, 0, -DRAW_DEEP, 0, 1, 0, 0, -DRAW_DEEP, 0, 0, 1, 0, -DRAW_DEEP, 0, 0, 0,
            1, 0 });//w w w  .  ja  v a 2 s  . c  om
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));
    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(srcBitmap, 0, 0, paint);
    return new BitmapDrawable(bmp);
}

From source file:Main.java

static public void setImageColor(ImageView view, Bitmap sourceBitmap, int rgbcolor)// ,Bitmap sourceBitmap)
{
    if (sourceBitmap != null) {
        float R = Color.red(rgbcolor);
        float G = Color.green(rgbcolor);
        float B = Color.blue(rgbcolor);

        Log.v("R:G:B", R + ":" + G + ":" + B); //

        float[] colorTransform = { R / 255f, 0, 0, 0, 0, // R color
                0, G / 255f, 0, 0, 0 // G color
                , 0, 0, B / 255f, 0, 0 // B color
                , 0, 0, 0, 1f, 0f };//from  ww w  .j  a  v a2  s . c om

        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0f); // Remove Colour

        colorMatrix.set(colorTransform);
        ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);

        Bitmap mutableBitmap = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true);
        view.setImageBitmap(mutableBitmap);
        Canvas canvas = new Canvas(mutableBitmap);
        canvas.drawBitmap(mutableBitmap, 0, 0, paint);

    }
}

From source file:com.ifoer.util.NetPOSPrinter.java

public Bitmap bitmapDuiBi(Bitmap bp) {
    ColorMatrix cm = new ColorMatrix();
    Bitmap bmp = Bitmap.createBitmap(bp.getWidth(), bp.getHeight(), Config.ARGB_8888);
    cm.set(new float[] { 2.0f, 0.0f, 0.0f, 0.0f, 50.0f, 0.0f, 2.0f, 0.0f, 0.0f, 50.0f, 0.0f, 0.0f, 2.0f, 0.0f,
            50.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f });
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    new Canvas(bmp).drawBitmap(bp, 0.0f, 0.0f, paint);
    return bmp;/*from  ww w. j  av a2  s .  c om*/
}