在SharpDX.Color中将颜色名称作为字符串传递 [英] Pass color name as string in SharpDX.Color

查看:110
本文介绍了在SharpDX.Color中将颜色名称作为字符串传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个颜色名称作为字符串(例如"Black").必须为我的Metro应用程序将该颜色名称转换为SharpDX.Color.现在以下列方式尝试

i am getting a color name as string (like "Black"). have to convert that color name as SharpDX.Color for my Metro app. now trying in following ways,

1)SharpDX.Color.FromRgba(颜色的int或uint值)
2)SharpDX.Color.FromArgb(颜色的int或uint值)

1)SharpDX.Color.FromRgba(int or uint value of color)
2)SharpDX.Color.FromArgb(int or uint value of color)

是否可以通过这种方式执行此操作?或其他任何最佳方式来做到这一点.

is it possible to do this in this way.? or any other best way to done this.??

推荐答案

使用枚举解析和System.Drawing可以提供帮助,虽然不是很好,但是可以使用:

Using Enum Parse and System.Drawing can help, it's not great but that would work:

KnownColor colorenum = (KnownColor)Enum.Parse(typeof(KnownColor),"Black");

Color4 bgcolor = new Color4(Color.FromKnownColor(colorenum).ToArgb());

否则,您可以使用字符串作为键和SharpDX.Color4作为值来构建自定义词典,并创建自己的颜色列表.

Otherwise you can build a custom Dictionary with string as key and SharpDX.Color4 as value, and create your own list of colors.

这篇关于在SharpDX.Color中将颜色名称作为字符串传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆