diff --git a/context.go b/context.go index 247d6b4..6ba4120 100644 --- a/context.go +++ b/context.go @@ -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) { diff --git a/util.go b/util.go index 8d340fa..3cd3258 100644 --- a/util.go +++ b/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 }