Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从图像中获取像素和设置像素作为HSB而不是RGB?_C#_.net - Fatal编程技术网

C# 如何从图像中获取像素和设置像素作为HSB而不是RGB?

C# 如何从图像中获取像素和设置像素作为HSB而不是RGB?,c#,.net,C#,.net,有没有快速的方法,或者我必须手动转换它们?谢谢。您可以使用如下扩展方法: Color c = Color.FromArgb(1, 2, 3); float h, s, b; h = c.GetHue(); s = c.GetSaturation(); b = c.GetBrightness(); public static class Extensions { public static Tuple<float, float, float> GetPixelHSB(this

有没有快速的方法,或者我必须手动转换它们?谢谢。

您可以使用如下扩展方法:

Color c = Color.FromArgb(1, 2, 3);
float h, s, b;
h = c.GetHue();
s = c.GetSaturation();
b = c.GetBrightness();
public static class Extensions
{
    public static Tuple<float, float, float> GetPixelHSB(this Bitmap bitmap, int x, int y)
    {
        Color c = bitmap.GetPixel(x, y);
        float h, s, b;
        h = c.GetHue();
        s = c.GetSaturation();
        b = c.GetBrightness();

        return Tuple.Create<float, float, float>(h, s, b);
    }

    public static void SetPixelHSB(this Bitmap bitmap, int x, int y, Tuple<float, float, float> hsb)
    {
        bitmap.SetPixelHSB(x, y, hsb.Item1, hsb.Item2, hsb.Item3);
    }

    public static void SetPixelHSB(this Bitmap bitmap, int x, int y, float h, float s, float b)
    {
        Color c = ColorFromHSBFunction(h, s, b);
        bitmap.SetPixel(x, y, c);
    }
}
公共静态类扩展
{
公共静态元组GetPixelHSB(此位图,int x,int y)
{
颜色c=位图.GetPixel(x,y);
浮子h、s、b;
h=c.GetHue();
s=c.GetSaturation();
b=c.GetBrightness();
返回Tuple.Create(h,s,b);
}
公共静态void SetPixelHSB(此位图,int x,int y,Tuple hsb)
{
SetPixelHSB(x,y,hsb.Item1,hsb.Item2,hsb.Item3);
}
公共静态void SetPixelHSB(此位图位图,int x,int y,float h,float s,float b)
{
颜色c=颜色来自HSB功能(h、s、b);
设置像素(x,y,c);
}
}

可以找到一个
colorfromhsb功能

谢谢。这样,有没有快速转换回RGB的方法?请参阅SuperOli的答案,了解ColorFromHSB函数该方法不起作用。。全黑=x。但我可能会搜索另一个我已经这样做了,但我无法访问这段代码。也许你可以根据这篇文章编写你自己的函数:从HSV开始就是你要找的。别忘了GetSaturation()和GetBrightness()以浮点形式返回值(范围从0.0f到1.0f)。我提供给您的ColorFromHSB函数的链接将这些值视为0到100之间的整数。你需要调整这个函数使它工作。我试过了。但也许我访问该方法的代码是错误的。谢谢