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

查看:36
本文介绍了如何使用 .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天全站免登陆