1. 程式人生 > >Go:十六進位制顏色程式碼轉換為RGB值

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"))