相关疑难解决方法(0)

将System.Drawing.Color转换为RGB和Hex值

使用C#我试图开发以下两个.我这样做可能有一些问题,需要你的建议.另外,我不知道是否有任何现有的方法来做同样的事情.

private static String HexConverter(System.Drawing.Color c)
{
    String rtn = String.Empty;
    try
    {
        rtn = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
    }
    catch (Exception ex)
    {
        //doing nothing
    }

    return rtn;
}

private static String RGBConverter(System.Drawing.Color c)
{
    String rtn = String.Empty;
    try
    {
        rtn = "RGB(" + c.R.ToString() + "," + c.G.ToString() + "," + c.B.ToString() + ")";
    }
    catch (Exception ex)
    {
        //doing nothing
    }

    return rtn;
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

c# asp.net rgb system.drawing.color

115
推荐指数
4
解决办法
15万
查看次数

标签 统计

asp.net ×1

c# ×1

rgb ×1

system.drawing.color ×1