imagineerThat
imagineerThat

Reputation: 5553

How do I get the hex color from an RGB color?

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

Answers (1)

Shubham Srivastava
Shubham Srivastava

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

Related Questions