gpt4 book ai didi

silverlight - 如何在代码中将 "#00E4FF"转换为 Brush?

转载 作者:行者123 更新时间:2023-12-04 09:21:15 24 4
gpt4 key购买 nike

我需要将一些颜色(十六进制)转换为 Brush。
我需要在代码中做到这一点。

我该怎么做 ?

最佳答案

//this would be initialized somewhere else, I assume
string hex = "#00E4FF";

//strip out any # if they exist
hex = hex.Replace("#", string.Empty);

byte r = (byte)(Convert.ToUInt32(hex.Substring(0, 2), 16));
byte g = (byte)(Convert.ToUInt32(hex.Substring(2, 2), 16));
byte b = (byte)(Convert.ToUInt32(hex.Substring(4, 2), 16));

SolidColorBrush myBrush = new SolidColorBrush(Color.FromArgb(255, r, g, b));

关于silverlight - 如何在代码中将 "#00E4FF"转换为 Brush?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6211388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com