get Radiant Color - Android Graphics

Android examples for Graphics:Color

Description

get Radiant Color

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {
    public static int getRadiantColor(final int col1, final int col2,
            final int level, final int min, final int max) {
        final int diff = min - max;
        final int diffpercent = min - level;
        final float factor = Math.abs((float) diffpercent / (float) diff);

        final int diffa = Color.alpha(col1) - Color.alpha(col2);
        final int diffr = Color.red(col1) - Color.red(col2);
        final int diffg = Color.green(col1) - Color.green(col2);
        final int diffb = Color.blue(col1) - Color.blue(col2);

        final int a = Math.round(Color.alpha(col1) - diffa * factor);
        final int r = Math.round(Color.red(col1) - diffr * factor);
        final int g = Math.round(Color.green(col1) - diffg * factor);
        final int b = Math.round(Color.blue(col1) - diffb * factor);

        return Color.argb(a, r, g, b);
    }//ww  w  .  j ava 2s.  co m
}

Related Tutorials