如何将颜色转换为html颜色 [英] how to convert color to html color
本文介绍了如何将颜色转换为html颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
i希望从System.Drawing.Color转换为HTML颜色,我希望颜色代码不是颜色名称
hi
i want to convert from System.Drawing.Color to HTML color, i want the color code not the color name
MessageBox.Show(System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Red));
输出:红色
i想要:#FF0000
thanx
output: Red
i want: #FF0000
thanx
推荐答案
这是一个将红色更改为HTML输出的片段
Here is a snippet to change the color Red to the HTML output
using System.Drawing;
Color colorRed = ColorTranslator.FromHtml("Red");
Console.WriteLine("colorRed: " + colorRed);
string htmlHexColorValueThree = String.Format("#{0:X2}{1:X2}{2:X2}", colorRed.R, colorRed.G, colorRed.B);
Console.WriteLine("htmlHexColorValueThree: " + htmlHexColorValueThree);
尝试:
Try:
private static String ConverteToHex(System.Drawing.Color c)
{
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
这篇关于如何将颜色转换为html颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文