Example usage for android.graphics LightingColorFilter LightingColorFilter

List of usage examples for android.graphics LightingColorFilter LightingColorFilter

Introduction

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

Prototype

public LightingColorFilter(@ColorInt int mul, @ColorInt int add) 

Source Link

Document

Create a colorfilter that multiplies the RGB channels by one color, and then adds a second color.

Usage

From source file:Main.java

public static ColorFilter screen(int c) {
    return new LightingColorFilter(0xFFFFFFFF - c, c);
}

From source file:Main.java

public static Bitmap changeImageColor(Bitmap sourceBitmap, int color) {
    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1,
            sourceBitmap.getHeight() - 1);
    Paint p = new Paint();
    p.setColor(color);/*from w  ww .  j  a  v  a 2s  . com*/
    ColorFilter filter = new LightingColorFilter(color, 1);

    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, p);
    return resultBitmap;
}

From source file:Main.java

public static Bitmap changeBitmapColor(@NonNull Bitmap sourceBitmap, @IntegerRes int color) {

    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1,
            sourceBitmap.getHeight() - 1);
    Paint p = new Paint();
    ColorFilter filter = new LightingColorFilter(color, 1);
    p.setColorFilter(filter);/*w  w w  .  j a  v a2s .co  m*/

    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, p);
    return resultBitmap;
}

From source file:Main.java

/**
 * TODO write documentation//from  w w  w.ja  v  a2  s. co  m
 *
 * @param sourceBitmap
 * @param color
 * @return
 */
public static Bitmap overlayColor(Bitmap sourceBitmap, int color) {
    Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight());
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);
    return mutableBitmap;
}

From source file:Main.java

/**
 * ATTENTION: DON'T USE THIS METHOD BECAUSE IT HAS BAD PERFORMANCES.
 *
 * @param source The original Bitmap.//from   w  ww.j av a2  s  . co  m
 * @param color  Color to overlay.
 * @return the result image.
 */
@Deprecated
private static Bitmap overlayColor(Bitmap source, int color) {
    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);
    return mutableBitmap;
}

From source file:Main.java

/**
 * ---------------------------------------------------------------------------
 * USE THIS METHOD AND NOT THE OLDER VERSION CALLED: "overlayColorOnGrayScale"
 * ---------------------------------------------------------------------------
 * Method to overlay color on a gray scale Bitmap.
 * This method creates automatically a gray scale bitmap from {@code source}.
 *
 * @param source The original colored Bitmap.
 * @param color  Color to overlay.//www.  j  a  va 2s.  co  m
 * @return A colored gray scale Bitmap.
 */
public static Bitmap overlayColorOnGrayScale(Bitmap source, int color) {
    Bitmap newBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);

    Canvas canvas = new Canvas(mutableBitmap);
    canvas.drawBitmap(source, 0, 0, getGrayScalePaint());

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);

    return mutableBitmap;
}

From source file:Main.java

/**
 * Method to overlay a color on a gray scale Bitmap, passed as a resource id {@code id}.
 * If you want to call this method from a Fragment/Activity call it in this way:
 * overlayColorOnGrayScale(getResources(), R.drawable.your_image, Color.RED)
 *
 * @param res   A reference to Resources.
 * @param id    The id of a drawable image.
 * @param color Color to overlay.//from  w ww .  j ava2  s .com
 * @return A colored gray scale Bitmap.
 * @throws IOException
 */
public static Bitmap overlayColorOnGrayScale(Resources res, int id, int color) throws IOException {
    Bitmap mutableBitmap = getMutableBitmap(res, id);

    Canvas canvas = new Canvas(mutableBitmap);
    canvas.drawBitmap(mutableBitmap, 0, 0, getGrayScalePaint());

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);

    return mutableBitmap;
}

From source file:com.example.domiter.fileexplorer.dialog.BaseDialogFragment.java

/**
 * Overrides tint set with tintDrawable().
 *//*  w w w. j a  v a 2  s . c  o m*/
private Drawable lightenDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    Drawable newDrawable = drawable.getConstantState().newDrawable().mutate();
    newDrawable
            .setColorFilter(new LightingColorFilter(Color.rgb(255, 255, 255), Color.argb(200, 255, 255, 255)));

    return newDrawable;
}

From source file:com.grarak.rom.switcher.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w ww  . j  a  v a  2 s. c  o  m*/

    progressBar = new ProgressBar(this);
    progressBar.getIndeterminateDrawable().setColorFilter(
            new LightingColorFilter(0xFF000000, getResources().getColor(android.R.color.white)));
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));

    new Task().execute();
}

From source file:at.amartinz.hardware.sensors.BaseSensor.java

public Drawable getSensorImage() {
    final int color;

    // local tint overrides global tint
    if (mIconTint != Integer.MIN_VALUE) {
        color = mIconTint;/*  w ww .j av a2s . c o  m*/
    } else {
        color = sIconTintGlobal;
    }

    final Drawable drawable = ContextCompat.getDrawable(getContext(), getImageResourceId()).mutate();
    drawable.setColorFilter(new LightingColorFilter(Color.BLACK, color));
    return drawable;
}