c sharp 写一个HSV转RGB
时间: 2023-02-11 11:31:07 浏览: 263
下面是C#代码实现HSV转RGB的示例:
```c#
using System;
using System.Drawing;
public static class HsvToRgb
{
public static Color Convert(double hue, double saturation, double value)
{
int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
double f = hue / 60 - Math.Floor(hue / 60);
value = value * 255;
int v = Convert.ToInt32(value);
int p = Convert.ToInt32(value * (1 - saturation));
int q = Convert.ToInt32(value * (1 - f * saturation));
int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));
if (hi == 0)
return Color.FromArgb(255, v, t, p);
else if (hi == 1)
return Color.FromArgb(255, q, v, p);
else if (hi == 2)
return Color.FromArgb(255, p, v, t);
else if (hi == 3)
return Color.FromArgb(255, p, q, v);
else if (hi == 4)
return Color.FromArgb(255, t, p, v);
else
return Color.FromArgb(255, v, p, q);
}
}
```
使用时调用HsvToRgb.Convert(hue,saturation,value)函数,传入hue(色相),saturation(饱和度),value(亮度)三个值,返回值为RGB格式的Color类型。
阅读全文