Reputation: 5553
I am reading an image and getting its colors in RGB via image/color
. However, I want to convert a color to hex triplet. How do I do this?
img, err := jpeg.Decode(someImg)
color := img.At(x, y) # I would like to convert this from RGB to hex
Upvotes: 4
Views: 1786
Reputation: 1877
Hex is just hexadecimal representation of RGB values you can simply do something like
fmt.Printf("#%02x%02x%02x", R, G, B)
Play Link: https://play.golang.org/p/bU510RaYle8
Upvotes: 5