/// <summary>
/// 将十六进制颜色值转换为 byte[] 数组
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public static byte[] HexToBytes(string hex)
{
// 去除可能的#字符
hex = hex.TrimStart('#');
int hexValue = Convert.ToInt32(hex, 16);
byte red = (byte)((hexValue >> 16) & 0xFF);
byte green = (byte)((hexValue >> 8) & 0xFF);
byte blue = (byte)(hexValue & 0xFF);
return new byte[] { red, green, blue };
}
C# 将十六进制颜色值转换为RGB
最新推荐文章于 2023-12-13 15:14:31 发布