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
? Also I notice when I remove the +rgb.Green
it works
// rgb.Red, rgb.Green, rgb.Blue are byte types
// h, delta are double
rgb.Red = Convert.ToByte(Math.Round((h - 4) * delta)) + rgb.Green;
public struct RGBColor
{
public byte Red { get; set; }
public byte Green { get; set; }
public byte Blue { get; set; }
}
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.
Doesn't byte + byte = byte?
Nope, because it may overflow (> 255), that's why this operation returns an Int32. You could cast the result back to byte at your own risk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With