如何在.NET Standard 2.0中将颜色转换为HTML颜色



如何在.NET Standard 2.0中将颜色转换为HTML颜色,谢谢u.

是指在.net Core中执行相同功能的任何方式,类似于下面的代码:

System.Drawing.ColorTranslator.ToHtml(color);

在DotNet框架中?

我不确定你的实际问题是什么,顺便说一下,让你知道,

System.Drawing.ColorTranslator.ToHtml(color);

在1.1版到4.8版的Dotnet Framework支持下,请参阅Microsoft文档(https://learn.microsoft.com/en-us/dotnet/api/system.drawing.colortranslator.tohtml?view=dotnet-plat-ext-3.1(

我根据原始System.Drawing.ColorTranslator源代码对以下代码进行了调整:

public static string ToHtml(System.Drawing.Color c)
{
var xResult = string.Empty;
if (c.IsEmpty)
{
return xResult;
}
xResult = ((!c.IsNamedColor) ? ("#" + c.R.ToString("X2", null) + c.G.ToString("X2", null) + c.B.ToString("X2", null)) : ((!(c == System.Drawing.Color.LightGray)) ? c.Name : "LightGrey"));
return xResult;
}

最新更新