且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将RGB图像更改为HSI

更新时间:2023-01-27 23:06:06

对于这种类型的图像处理,你真的应该使用不安全的代码(指针) )在你的嵌套循环中。在此搜索页面上查看有关CodeProject的三篇文章:[ ^ ]。



您可以在这里尝试RGB< => HSL算法:[ ^ ]。



您还可以使用API​​调用:
For image processing of this type you really should be using "unsafe" code (pointers) in your nested loop. See the three articles on CodeProject on this search page: [^].

You might try the RGB<=>HSL algorithm here: [^].

There is an API call you can use also:
[DllImport("shlwapi.dll")]
static extern void ColorRGBToHLS(int RGB, ref int H, ref int L, ref int S);

但是,请参阅此处的示例代码对其输出的重要修改:[ ^ ]。



您是否知道.NET提供RGB到HSL转换功能?示例:

But, see the sample code here for an important modification of its output:[^].

Are you aware that .NET supplies RGB to HSL conversion functions ? Example:

private struct hslColorValues
{
    private float H;
    private float S;
    private float B;

    public hslColorValues(float hue, float saturation, float brightness)
    {
        H = hue;
        S = saturation;
        B = brightness;
    }
}

private hslColorValues rgbToHsl(string colorName)
{
    Color color = Color.FromName(colorName);
    return new hslColorValues(color.GetHue(), color.GetSaturation(), color.GetBrightness());
}