我有这段代码
string hex = "#FFFFFF";
Color _color = System.Drawing.ColorTranslator.FromHtml(hex);
我需要在Microsoft.Xna.Framework
使用以前的代码我收到此错误:
Cannot implicitly convert type 'System.Drawing.Color' to 'Microsoft.Xna.Framework.Color'
any idea how to solve this?
答案 0 :(得分:3)
这是你需要的吗?
public Microsoft.Xna.Framework.Graphics.Color XNAColor(System.Drawing.Color color)
{
return new Microsoft.Xna.Framework.Graphics.Color(color.R, color.G, color.B, color.A)
}
答案 1 :(得分:1)
解决了这个
private Microsoft.Xna.Framework.Color ConvertFromHex(string s)
{
if (s.Length != 7)
return Color.Gray;
int r = Convert.ToInt32(s.Substring(1, 2), 16);
int g = Convert.ToInt32(s.Substring(3, 2), 16);
int b = Convert.ToInt32(s.Substring(5, 2), 16);
return new Color(r, g, b);
}