我认为没有充分的理由。首先,我认为深入研究代码会提供一些见解,但我能找到的只是检查以确保 alpha、red、green 和 blue 的值在 [0 ..255] 范围,否则抛出异常。然后在内部调用MakeArgb 方法,该方法确实使用byte:
/// <summary>
/// [...]
/// Although this method allows a 32-bit value
/// to be passed for each component, the value of each
/// component is limited to 8 bits.
/// </summary>
public static Color FromArgb(int alpha, int red, int green, int blue)
{
Color.CheckByte(alpha, "alpha");
Color.CheckByte(red, "red");
Color.CheckByte(green, "green");
Color.CheckByte(blue, "blue");
return new Color(Color.MakeArgb((byte)alpha, (byte)red, (byte)green, (byte)blue), Color.StateARGBValueValid, null, (KnownColor)0);
}
private static long MakeArgb(byte alpha, byte red, byte green, byte blue)
{
return (long)((ulong)((int)red << 16 | (int)green << 8 | (int)blue | (int)alpha << 24) & (ulong)-1);
}
private static void CheckByte(int value, string name)
{
if (value < 0 || value > 255)
{
throw new ArgumentException(SR.GetString("InvalidEx2BoundArgument",
name,
value,
0,
255));
}
}
我猜它在早期就变成了这种情况(我们在这里谈论的是 .NET 1.0),然后它就卡住了。
此外,还有FromArgb(int) 重载,它允许您使用一个 32 位值设置所有 32 位。奇怪的是,这是int 而不是unsigned int。