Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Color;

public class Main {
    /**
     *  Convert RGB Color to a HSV values. 
     *  
     *  <li>H (Hue) is specified as degrees in the range 0 - 360.</li>
     *  <li>S (Saturation) is specified as a percentage in the range 1 - 100.</li>
     *  <li>V (Value) is specified as a percentage in the range 1 - 100.</li>
     *
     *  @param color the RGB color
     *  @return the HSV values
     */
    public static int[] colorToHSV(int color) {
        int[] hsv = new int[3];
        float[] hsv_float = new float[3];

        Color.colorToHSV(color, hsv_float);

        hsv[0] = (int) Math.round(hsv_float[0]);
        hsv[1] = (int) Math.round(hsv_float[1] * 100);
        hsv[2] = (int) Math.round(hsv_float[2] * 100);

        hsv[0] = (int) (hsv_float[0]);
        hsv[1] = (int) (hsv_float[1] * 100);
        hsv[2] = (int) (hsv_float[2] * 100);

        return hsv;
    }
}