RGB to HSL and back, calculation problems

后端 未结 3 710
半阙折子戏
半阙折子戏 2020-12-09 21:40

I\'m trying to convert RGB to HSL and I also want to convert from HSL to RGB, I have written a class for it but if I do RGB->HSL->RGB to try if it works I get a different va

3条回答
  •  [愿得一人]
    2020-12-09 22:03

    Common bug. You've got

        public static HSLColor FromRGB(Byte R, Byte G, Byte B)
        {
            float _R = (R / 255);
            float _G = (G / 255);
            float _B = (B / 255);
    

    Tell me precisely what values of R can result in _R not being 0. (Hint: there's only one).

    Edit: you've got the same problem in ToRGB() with 1/3.

提交回复
热议问题