赞
踩
光谱颜色转换RGB展示
紫外&极紫外&X射线用黑色表示
红外用红色表示
/// <summary>
/// 波长转RGB色
/// </summary>
/// <param name="lambda"></param>
/// <returns></returns>
public static Color WaveLengthToRGB(int lambda)
{
double r = 0;
double g = 0;
double b = 0;
if ((lambda >= 380.0) && (lambda < 440.0))
{
r = -1.0 * (lambda - 440.0) / (440.0 - 380.0);
g = 0.0;
b = 1.0;
}
else if ((lambda >= 440.0) && (lambda < 490.0))
{
r = 0.0;
g = (lambda - 440.0) / (490.0 - 440.0);
b = 1.0;
}
else if ((lambda >= 490.0) && (lambda < 510.0))
{
r = 0.0;
g = 1.0;
b = -1.0 * (lambda - 510.0) / (510.0 - 490.0);
}
else if ((lambda >= 510.0) && (lambda < 580.0))
{
r = (lambda - 510.0) / (580.0 - 510.0);
g = 1.0;
b = 0.0;
}
else if ((lambda >= 580.0) && (lambda < 645.0))
{
r = 1.0;
g = -1.0 * (lambda - 645.0) / (645.0 - 580.0);
b = 0.0;
}
else if ((lambda >= 645.0) && (lambda <= 780.0))
{
r = 1.0;
g = 0.0;
b = 0.0;
}
if ((lambda >= 380.0) && (lambda < 420.0))
{
double attenuation = 0.3 + 0.7 * (lambda - 380) / (420 - 380);
r = r * attenuation;
g = 0.0;
b = 1.0 * attenuation;
}
else if ((lambda >= 701.0) && (lambda < 780.0))
{
double attenuation = 0.30 + 0.70 * (780.0 - lambda) / (780.0 - 700.0);
r = r * attenuation;
g = 0.0;
b = 0.0;
}
if (lambda < 380)
{//紫外
r = 1;
g = 1;
b = 1;
}
else if (lambda > 780)
{//红外
r = 1;
g = 0;
b = 0;
}
int R = (int)(r * 255);
int G = (int)(g * 255);
int B = (int)(b * 255);
return Color.FromArgb(R, G, B);//颜色
}
效果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。