如何使用.NET从十六进制颜色代码获取颜色? [英] How do I get the color from a hexadecimal color code using .NET?

查看:142
本文介绍了如何使用.NET从十六进制颜色代码获取颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从十六进制颜色代码中获取颜色(例如#FFDFD991 )?

How can I get a color from a hexadecimal color code (e.g. #FFDFD991)?

我是读取文件并获取十六进制颜色代码。我需要为十六进制颜色代码创建相应的 System.Windows.Media.Color 实例。在框架中是否有内置的方法来实现这个功能?

I am reading a file and am getting a hexadecimal color code. I need to create the corresponding System.Windows.Media.Color instance for the hexadecimal color code. Is there an inbuilt method in the framework to do this?

推荐答案

我假设这是一个ARGB代码...你是引用 System.Drawing.Color System.Windows.Media.Color ?后者用于WPF中。我还没有看到任何人提到它,所以以防万一你正在寻找它:

I'm assuming that's an ARGB code... Are you referring to System.Drawing.Color or System.Windows.Media.Color? The latter is used in WPF for example. I haven't seen anyone mention it yet, so just in case you were looking for it:

using System.Windows.Media;

Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");

这篇关于如何使用.NET从十六进制颜色代码获取颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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