我正在寻找一种方法,将 C# 中的 ColorDialog Box 返回的颜色代码转换为 KML/KMZ 文件格式使用的颜色格式。任何信息将不胜感激!!
最佳答案
经过几个小时的研究,我已经回答了我自己的问题。
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;
}
我愿意寻找更有效的方法来获取颜色值
关于c# - 如何将 ColorDialog 颜色转换为 KML 颜色格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902294/