mirror of
https://github.com/taigrr/simplecolorpalettes.git
synced 2026-04-01 20:49:11 -07:00
Create toHex apis
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package simplecolor
|
package simplecolor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -22,6 +23,17 @@ func (s SimplePalette) ToPalette() color.Palette {
|
|||||||
return color.Palette(x)
|
return color.Palette(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c SimpleColor) ToHex() string {
|
||||||
|
return "#" + fmt.Sprintf("%06X", c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c SimpleColor) ToShortHex() string {
|
||||||
|
value := c >> 16 & 0xF
|
||||||
|
value += c >> 8 & 0xF
|
||||||
|
value += c & 0xF
|
||||||
|
return "#" + fmt.Sprintf("%06X", value)
|
||||||
|
}
|
||||||
|
|
||||||
func (s SimpleColor) RGBA() (r, g, b, a uint32) {
|
func (s SimpleColor) RGBA() (r, g, b, a uint32) {
|
||||||
return uint32(s) >> 16 & 0xFF, uint32(s) >> 8 & 0xFF, uint32(s) & 0xFF, 0xFF
|
return uint32(s) >> 16 & 0xFF, uint32(s) >> 8 & 0xFF, uint32(s) & 0xFF, 0xFF
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user