我正在读取图像并通过 image/color
以 RGB 形式获取其颜色。但是,我想将 color 转换为 hex triplet。我该怎么做?
img, err := jpeg.Decode(someImg)
color := img.At(x, y) # I would like to convert this from RGB to hex
答案 0 :(得分:2)
Hex 只是 RGB 值的十六进制表示,您可以简单地执行类似的操作
fmt.Printf("#%02x%02x%02x", R, G, B)