Go:十六进制颜色代码转换为RGB值

func ColorToRGB(colorstr string) (red, green, blue int) {
    colorstr = strings.TrimPrefix(colorstr, "#")
    color64, err := strconv.ParseInt(colorstr, 16, 32)
    if err != nil {
        return
    }
    color := int(color64)
    return color >> 16, (color & 0x00FF00) >> 8, color & 0x0000FF
}
//使用方法
fmt.Println(ColorToRGB("#003366"))

猜你喜欢

转载自www.cnblogs.com/chenyachao/p/10012791.html
今日推荐