Java HSV Color to HSB hsv2rgb(float h, float s, float v)

Here you can find the source of hsv2rgb(float h, float s, float v)

Description

hsvrgb

License

Open Source License

Declaration

public static int[] hsv2rgb(float h, float s, float v) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[] hsv2rgb(float h, float s, float v) {
        float c = v * s;
        float x = c * (1 - Math.abs((h / 60) % 2 - 1));
        float m = v - c;

        float r1 = 0, g1 = 0, b1 = 0;

        if (h < 60) {
            r1 = c;//from  w  w  w .java  2  s  . c  o m
            g1 = x;
            b1 = 0;
        } else if (h >= 60 && h < 120) {
            r1 = x;
            g1 = c;
            b1 = 0;
        } else if (h >= 120 && h < 180) {
            r1 = 0;
            g1 = c;
            b1 = x;
        } else if (h >= 180 && h < 240) {
            r1 = 0;
            g1 = x;
            b1 = c;
        } else if (h >= 240 && h < 300) {
            r1 = x;
            g1 = 0;
            b1 = c;
        } else if (h >= 300 && h < 360) {
            r1 = c;
            g1 = 0;
            b1 = x;
        }

        return new int[] { (int) ((r1 + m) * 255), (int) ((g1 + m) * 255), (int) ((b1 + m) * 255) };
    }
}

Related

  1. hsv2rgb(float h, float s, float v, float[] rgb)
  2. hsv2rgb_hex(float h, float s, float v)
  3. hsva(double hue, double saturation, double value, double alpha)
  4. HSVToColor(float[] hsv)