- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的游戏框架编写一个 HSVtoRGB 方法,在处理色调时,会发生这种情况 -> http://youtu.be/ACBwR_0iMWE .
这是代码。
public static Color HSVtoRGB(float hue, float saturation, float value, float alpha)
{
if(hue > 1 || saturation > 1 || value > 1) throw new Exception("values cannot be more than 1!");
if (hue < 0 || saturation < 0|| value < 0) throw new Exception("values cannot be less than 0!");
Color output = new Color();
if (Math.Abs(saturation) < 0.001)
{
output.R = (byte) (value*byte.MaxValue);
output.G = (byte) (value*byte.MaxValue);
output.B = (byte) (value*byte.MaxValue);
}
else
{
hue = hue/60f;
float f = hue - (int)hue;
float p = value*(1f - saturation);
float q = value*(1f - saturation*f);
float t = value*(1f - saturation*(1f - f));
switch ((int)hue)
{
case (0) :
output = new Color(value * 255, t * 255, p * 255, alpha);
break;
case (1):
output = new Color(q * 255, value * 255, p * 255, alpha);
break;
case (2):
output = new Color(p * 255, value * 255, t * 255, alpha);
break;
case (3):
output = new Color(p * 255, q * 255, value * 255, alpha);
break;
case (4):
output = new Color(t * 255, p * 255, value * 255, alpha);
break;
case (5):
output = new Color(value * 255, p * 255, q * 255, alpha);
break;
default :
throw new Exception("RGB color unknown!");
}
}
return output;
}
将 .001f
添加到色调时,它会导致它从红色变为黄色,但随后会一直保持黄色,直到它回滚到 0。请注意我使用的是 Microsoft。 Xna.Framework.Color
不是 System.Drawing.Color
。
供引用,这里是Flixel Power Tools的HSVtoRGB方法,基本上是我要复制的内容。
public static function HSVtoRGB(h:Number, s:Number, v:Number, alpha:uint = 255):uint
{
var result:uint;
if (s == 0.0)
{
result = getColor32(alpha, v * 255, v * 255, v * 255);
}
else
{
h = h / 60.0;
var f:Number = h - int(h);
var p:Number = v * (1.0 - s);
var q:Number = v * (1.0 - s * f);
var t:Number = v * (1.0 - s * (1.0 - f));
switch (int(h))
{
case 0:
result = getColor32(alpha, v * 255, t * 255, p * 255);
break;
case 1:
result = getColor32(alpha, q * 255, v * 255, p * 255);
break;
case 2:
result = getColor32(alpha, p * 255, v * 255, t * 255);
break;
case 3:
result = getColor32(alpha, p * 255, q * 255, v * 255);
break;
case 4:
result = getColor32(alpha, t * 255, p * 255, v * 255);
break;
case 5:
result = getColor32(alpha, v * 255, p * 255, q * 255);
break;
default:
FlxG.log("FlxColor Error: HSVtoRGB : Unknown color");
}
}
return result;
}
最佳答案
我根据您的代码编写了自己的 HSV->RGB 转换器...
(还有您指向 http://www.easyrgb.com/index.php?X=MATH&H=21#text21 的链接)
代码是:
public static Color HSVtoRGB(float hue, float saturation, float value, float alpha)
{
while (hue > 1f) { hue -= 1f; }
while (hue < 0f) { hue += 1f; }
while (saturation > 1f) { saturation -= 1f; }
while (saturation < 0f) { saturation += 1f; }
while (value > 1f) { value -= 1f; }
while (value < 0f) { value += 1f; }
if (hue > 0.999f) { hue = 0.999f; }
if (hue < 0.001f) { hue = 0.001f; }
if (saturation > 0.999f) { saturation = 0.999f; }
if (saturation < 0.001f) { return new Color(value * 255f, value * 255f, value * 255f); }
if (value > 0.999f) { value = 0.999f; }
if (value < 0.001f) { value = 0.001f; }
float h6 = hue * 6f;
if (h6 == 6f) { h6 = 0f; }
int ihue = (int)(h6);
float p = value * (1f - saturation);
float q = value * (1f - (saturation * (h6 - (float)ihue)));
float t = value * (1f - (saturation * (1f - (h6 - (float)ihue))));
switch (ihue)
{
case 0:
return new Color(value, t, p, alpha);
case 1:
return new Color(q, value, p, alpha);
case 2:
return new Color(p, value, t, alpha);
case 3:
return new Color(p, q, value, alpha);
case 4:
return new Color(t, p, value, alpha);
default:
return new Color(value, p, q, alpha);
}
}
有了它,我渲染了这个:
一些值得注意的事情:
关于c# - HSV 到 RGB 在黄色 C# 处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17080535/
我必须使用 opencv 开发 android 代码,代码相当于 MATLAB。因为我必须读取图像并将其转换为 HSV,我已经使用: Imgproc.cvtColor(temp, hsv , Im
我正在寻找从 RGB 到 HSV 的颜色空间转换器,特别是用于两种颜色空间的 0 到 255 范围。 最佳答案 我已经使用了很长时间 - 现在不知道它们是从哪里来的......请注意,输入和输出,除了
我正在使用 openCV 3.1.0(我试过 2.4.9,但有同样的问题)。我想将 HSV 垫输出到 jpeg: // .. Getting JPEG content into memory // J
我有这段代码可以将 RGB 转换为 HSV func rgbToHSV (_ r:Double, _ g:Double, _ b:Double) -> (Double, Double, Doubl
我不熟悉图像检测技术。我正在使用 java openCV 来检测图像中的颜色。我能够检测到黄色和红色。我从命中和试用方法中获得了值(value),这些方法工作正常。但我还想从下面的手图像中检测绿色、橙
我正在开发一款应用程序, children 需要在其中使用相机屏幕上的特定目标点来找到特定的颜色 - 有点像增强现实。我已经完成了所有工作,但使用了 RGB 颜色。对于每种颜色,红色、绿色、蓝色、黄色
我有一个将 RGB 颜色空间中的 vector 转换为 HSV 的函数 - 该例程通过了所有测试并且在绝大多数时间都有效。然而,崩溃报告表明它偶尔会失败(0.0001% 的调用或更少)。但是,由于此函
我正在开发一个应用程序,该应用程序创建的图像的色调、饱和度和值会根据不同的参数发生变化。出于性能原因,最好分别渲染色调、饱和度和值组件,然后使用 Photoshop 风格的混合模式(乘法、叠加、屏幕、
我正在使用 matplotlib 中的 HSV 颜色图来绘制一些向量场。有没有办法使 HSV 颜色变暗或变得更平滑,使它们看起来更像这样 比我原来的绘图颜色太亮: 最佳答案 简介 假设您正在尝试绘制这
我正在尝试遍历 HSV 图像,但它一直在崩溃。 Mat a=imread("play.jpg"); Mat hsvimage, hsvimage2,cont; cvtColor(a,
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭10 年前。 Improve th
我听说,如果您需要在软件上进行颜色分割(如果满足某些阈值规则,例如 R100、10<,则通过将像素设置为 1,从彩色图像创建二进制图像) B < 123) 最好先将图像转换为 HSV。这是真的吗?为什
我正在 win32 api 中创建一个应用程序,它将使用进度条。这个进度条应该改变它的颜色。从红色(左端)到绿色(右端),中间有一些黄色。 我搜索了一下,发现我应该使用 HSV 来实现这一点。我就是不
虽然我通常更喜欢 RGB 颜色空间而不是 HSV,但我希望 SKEmitterNode 发射具有最大饱和度和值的粒子,并且具有涵盖所有颜色的色调值。这可能吗? 我是 XCode、Swift 和 Spr
假设我有两种 RGB 颜色 (255,0,0) 和 (0,0,255),我还需要它们之间的 100 种颜色。我如何根据许多所需步骤生成 HSV 颜色值列表? 当前使用 python 3 我创建了以下代
我正在从如下图像创建一个 hsv 直方图。 - (void)processImageWithHsv:(Mat&)image; { Mat image_hsv; cvtColor(ima
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在寻找一种为 3 channel 矩阵的元素赋值的有效方法。特别是,我需要将 HSV 值分配给 2D cv::Mat 的元素,其初始化如下: cv::Mat clusterImage(height
我正在尝试使用 openCV 和 C++ 来均衡 HSV 图像的直方图。我知道有些带有 openCV 的库可以为我执行此操作,但我想手动尝试以了解该方法。 我假设均衡将在 HSV 图像的 V chan
所以我一直在尝试使用 HSV 在一定程度范围内循环颜色,但我似乎无法在颜色之间平滑过渡。理想情况下,我希望能够在特定的度数范围 (80-140) 内移动,并在 0.5 - 1 之间循环饱和度和值。老实
我是一名优秀的程序员,十分优秀!