HSV(0..255)为RGB(0..255)HSV、RGB

2023-09-11 07:14:25 作者:梦鸢

可能重复:   Algorithm以RGB转换为HSV和HSV到RGB?

可以再如何将HSV值转换为RGB当该值是0到255有人解释?此外,

Can someone explain on how to convert an HSV value to an RGB when the value is 0 to 255? Also,

有关的参考,我试图做到这一点在C ++中。

For reference, I am trying to do this in C++.

推荐答案

在这里找到 http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript

function hsvToRgb(h, s, v){
    var r, g, b;

    var i = Math.floor(h * 6);
    var f = h * 6 - i;
    var p = v * (1 - s);
    var q = v * (1 - f * s);
    var t = v * (1 - (1 - f) * s);

    switch(i % 6){
        case 0: r = v, g = t, b = p; break;
        case 1: r = q, g = v, b = p; break;
        case 2: r = p, g = v, b = t; break;
        case 3: r = p, g = q, b = v; break;
        case 4: r = t, g = p, b = v; break;
        case 5: r = v, g = p, b = q; break;
    }

    return [r * 255, g * 255, b * 255];
}

编辑:

我曾经写过一个颜色选择器和用于了解这一切。那时,我看着的Photoshop拾色器,试图围绕着十字移动,观察其变化HSV / RGB数,并计算出它们是如何工作。在这种情况下似乎的查找的,此时的主色调,色相,指向它。色调的值实际上是一定程度的在周期完全饱和颜色的启动用红色和红色结束。有与每个点重新presenting R,G和B,其中0度是R. R和G之间的三角形,它的黄色,R和B之间,它的品红色和B和G之间,它的青色。在那里,我们共有6种颜色。这些6种颜色是从案例0-5。

I once wrote a color picker and used to understand all these. Back then, I looked at photoshop color picker, tried moving around the cross hair, observe the changes in hsv/rgb numbers and figured out how they work. In this case i seems to locate at which point the main color, hue, is pointed it. The value of hue is actually a degree of fully saturated colors in cycle which starts with red and ends with red. There's a triangle with each point representing R,G and B where 0 degree is R. Between R and G, it's Yellow, between R and B, it's Magenta and between B and G, it's cyan. There we have total 6 colors. Those 6 colors are from case 0 through 5.

 
精彩推荐