如何将 ColorDialog 颜色转换为 KML 颜色格式

Nat*_* S. 5 c# kml visual-studio-2010 colordialog kmz

我\xe2\x80\x99m 正在寻找一种方法,将 C# 中的 ColorDialog Box 返回的颜色代码转换为 KML/KMZ 文件格式使用的颜色格式。任何信息,将不胜感激!!

\n

Nat*_* S. 4

经过几个小时的研究,我已经回答了我自己的问题。

Kml 使用 8 位十六进制颜色格式。红色的传统十六进制格式看起来像#FF0000。在 Kml 中,红色看起来像 FF0000FF。前 2 位数字表示不透明度(alpha)。颜色格式为AABBGGRR。我正在寻找一种方法来设置颜色和不透明度并将其返回到要放置在 KML 属性中的字符串中。这是我的解决方案。

string color
string polyColor;
int opacity;
decimal percentOpacity;
string opacityString;

//This allows the user to set the color with a colorDialog adding the chosen color to a string in HEX (without opacity (BBGGRR))
private void btnColor_Click(object sender, EventArgs e)
{
    if (colorDialog1.ShowDialog() == DialogResult.OK)
    {
        btnColor.BackColor = colorDialog1.Color;
        Color clr = colorDialog1.Color;
        color = String.Format("{0:X2}{1:X2}{2:X2}", clr.B, clr.G, clr.R);
    }
}

//This method takes the Opacity (0% - 100%) set by a textbox and gets the HEX value. Then adds Opacity to Color and adds it to a string.
private void PolyColor()
{
    percentOpacity = ((Convert.ToDecimal(txtOpacity.Text) / 100) * 255);
    percentOpacity = Math.Floor(percentOpacity);  //rounds down
    opacity = Convert.ToInt32(percentOpacity);
    opacityString = opacity.ToString("x");
    polyColor = opacityString + color;

}
Run Code Online (Sandbox Code Playgroud)

我愿意寻求更有效的方法来获取颜色值