saturate color Relative to an offset - Android Graphics

Android examples for Graphics:Color Operation

Description

saturate color Relative to an offset

Demo Code


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

public class Main {
    public static int saturateRelative(int color, float saturationOffset) {
        float[] hsv = new float[3];
        Color.RGBToHSV(Color.red(color), Color.green(color),
                Color.blue(color), hsv);
        hsv[1] += saturationOffset;//ww  w.ja v  a2s  .c  o  m
        if (hsv[1] > 1.0f) {
            hsv[1] = 1.0f;
        } else if (hsv[1] < 0.0f) {
            hsv[1] = 0.0f;
        }
        return Color.HSVToColor(Color.alpha(color), hsv);
    }
}

Related Tutorials