support alpha in SetHexColor
This commit is contained in:
parent
d930cb4052
commit
a46d144fed
@ -141,8 +141,8 @@ func (dc *Context) SetColor(c color.Color) {
|
||||
}
|
||||
|
||||
func (dc *Context) SetHexColor(x string) {
|
||||
r, g, b := parseHexColor(x)
|
||||
dc.SetRGB255(r, g, b)
|
||||
r, g, b, a := parseHexColor(x)
|
||||
dc.SetRGBA255(r, g, b, a)
|
||||
}
|
||||
|
||||
func (dc *Context) SetRGBA255(r, g, b, a int) {
|
||||
|
7
util.go
7
util.go
@ -48,8 +48,9 @@ func imageToRGBA(src image.Image) *image.RGBA {
|
||||
return dst
|
||||
}
|
||||
|
||||
func parseHexColor(x string) (r, g, b int) {
|
||||
func parseHexColor(x string) (r, g, b, a int) {
|
||||
x = strings.TrimPrefix(x, "#")
|
||||
a = 255
|
||||
if len(x) == 3 {
|
||||
format := "%1x%1x%1x"
|
||||
fmt.Sscanf(x, format, &r, &g, &b)
|
||||
@ -61,6 +62,10 @@ func parseHexColor(x string) (r, g, b int) {
|
||||
format := "%02x%02x%02x"
|
||||
fmt.Sscanf(x, format, &r, &g, &b)
|
||||
}
|
||||
if len(x) == 8 {
|
||||
format := "%02x%02x%02x%02x"
|
||||
fmt.Sscanf(x, format, &r, &g, &b, &a)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user