我想创建 SolidColorBrush 从十六进制值,如 # ffacc。我该如何做到这一点?
在 MSDN 上,我收到了:
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);
因此我写道(考虑到我的方法接收的颜色是 #ffaacc
) :
Color.FromRgb(
Convert.ToInt32(color.Substring(1, 2), 16),
Convert.ToInt32(color.Substring(3, 2), 16),
Convert.ToInt32(color.Substring(5, 2), 16));
但是这给出了错误的答案
The best overloaded method match for 'System.Windows.Media.Color.FromRgb(byte, byte, byte)' has some invalid arguments
还有3个错误: Cannot convert int to byte.
那么 MSDN 的例子是如何工作的呢?