What's wrong with this expression? Cannot implicitly convert type 'int' to 'byte'

后端 未结 5 1212
后悔当初
后悔当初 2020-12-19 02:29

I am getting the error \"Cannot implicitly convert type \'int\' to \'byte\'. An explicit conversion exists (are you missing a cast?)\". Doesn\'t byte + byte = byte

5条回答
  •  佛祖请我去吃肉
    2020-12-19 02:53

    Adding two bytes produces an integer in C#. Convert the entire thing back to a byte.

    rgb.Red = (byte)(Convert.ToByte(Math.Round((h - 4) * delta)) + rgb.Green);
    

    See byte + byte = int... why? for more information.

提交回复
热议问题