45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 编程代码 > 阅读资讯:怎么样计算波长到RGB?

怎么样计算波长到RGB?

2016-08-25 20:18:34 来源:www.45fan.com 【

怎么样计算波长到RGB?

波长到RGB的算法

作者: CruelYoung

参考: http://www.midnightkite.com/color.html

更多访问: http://www.image2003.com

C# 编写

效果图:

怎么样计算波长到RGB?

相关的算法代码

private Color WavelenghToRGB(int Wavelength)
{
double Gamma = 0.8;
int IntensityMax = 255;

double Blue;
double Green;
double Red;
double factor;

if(Wavelength >= 380 && Wavelength <= 439)
{
Red = -(Wavelength - 440d) / (440d - 350d);
Green = 0.0;
Blue = 1.0;
}
else if(Wavelength >= 440 && Wavelength <= 489)
{
Red = 0.0;
Green = (Wavelength - 440d) / (490d - 440d);
Blue = 1.0;
}
else if(Wavelength >= 490 && Wavelength <= 509)
{
Red = 0.0;
Green = 1.0;
Blue = -(Wavelength - 510d) / (510d - 490d);
}
else if(Wavelength >= 510 && Wavelength <= 579)
{
Red = (Wavelength - 510d) / (580d - 510d);
Green = 1.0;
Blue = 0.0;
}
else if(Wavelength >= 580 && Wavelength <= 644)
{
Red = 1.0;
Green = -(Wavelength - 645d) / (645d - 580d);
Blue = 0.0;
}
else if(Wavelength >= 645 && Wavelength <= 780)
{
Red = 1.0;
Green = 0.0;
Blue = 0.0;
}
else
{
Red = 0.0;
Green = 0.0;
Blue = 0.0;
}

if(Wavelength >= 350 && Wavelength <= 419)
{
factor = 0.3 + 0.7*(Wavelength - 380d) / (420d - 380d);
}
else if(Wavelength >= 420 && Wavelength <= 700)
{
factor = 1.0;
}
else if(Wavelength >= 701 && Wavelength <= 780)
{
factor = 0.3 + 0.7*(780d - Wavelength) / (780d - 700d);
}
else
{
factor = 0.0;
}

int R = this.Adjust(Red, factor, IntensityMax, Gamma);
int G = this.Adjust(Green, factor, IntensityMax, Gamma);
int B = this.Adjust(Blue, factor, IntensityMax, Gamma);

return Color.FromArgb(R, G, B);
}

private int Adjust(double Color, double Factor, int IntensityMax, double Gamma)
{
if(Color == 0.0)
{
return 0;
}
else
{
return (int) Math.Round(IntensityMax * Math.Pow(Color * Factor, Gamma));
}

}


本文地址:http://www.45fan.com/bcdm/67612.html
Tags: rgb 算法 波长
编辑:路饭网
推广内容
推荐阅读
热门推荐
推荐文章
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部