Bro*_*ell 0 android google-maps colors marker
我想为谷歌地图标记使用自定义十六进制颜色,但我看到您只能使用 0-360 和 10 个预定义的色调颜色。有什么方法可以将标记颜色更改为十六进制颜色,或者至少将十六进制值转换为色调以便我可以使用它?我已经知道如何为标记设置色调颜色,但不是十六进制颜色。
以下代码显示了一个示例。它基于使用 JavaScript 的这个很棒的答案:https : //stackoverflow.com/a/3732187/1207156
public class Convert {
public static class Hsl {
public double h, s, l;
public Hsl(double h, double s, double l) {
this.h = h;
this.s = s;
this.l = l;
}
}
public static void main(String[] args) {
String color = "#c7d92c"; // A nice shade of green.
int r = Integer.parseInt(color.substring(1, 3), 16); // Grab the hex representation of red (chars 1-2) and convert to decimal (base 10).
int g = Integer.parseInt(color.substring(3, 5), 16);
int b = Integer.parseInt(color.substring(5, 7), 16);
double hue = rgbToHsl(r, g, b).h * 360;
System.out.println("The hue value is " + hue);
}
private static Hsl rgbToHsl(double r, double g, double b) {
r /= 255d; g /= 255d; b /= 255d;
double max = Math.max(Math.max(r, g), b), min = Math.min(Math.min(r, g), b);
double h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0; // achromatic
} else {
double d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
if (max == r) h = (g - b) / d + (g < b ? 6 : 0);
else if (max == g) h = (b - r) / d + 2;
else h = (r - g) / d + 4; // if (max == b)
h /= 6;
}
return new Hsl(h, s, l);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1549 次 |
| 最近记录: |