Skip to content

Commit

Permalink
Fix: color use rgba
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Aug 30, 2022
1 parent a6d519d commit 30f7dd0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"bytes"
"fmt"
"image"
"image/color"
"io"
"os"
Expand All @@ -17,7 +16,7 @@ import (
func main() {
pic := text2picture.NewPictureWithBackGround(text2picture.NewWhiteBackGround(500, 100), 320, 10, 5)
pic.DrawWithBlack("test 123\n4321...")
pic.DrawWithColor(0x60f2, "test color ... ")
pic.DrawWithColor(color.RGBA{255, 0, 0, 255}, "test color ... ")
pic.PointOffset(0, 5)
pic.DrawWithBlack("test offset\n")
f, err := os.OpenFile("./test.png", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
Expand Down
4 changes: 2 additions & 2 deletions backGround.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"image/draw"
)

func NewBackGroundWithColor(width, height int, _16bit_color uint16) *image.RGBA {
func NewBackGroundWithColor(width, height int, color color.RGBA) *image.RGBA {
rgba := image.NewRGBA(image.Rect(0, 0, width, height))
draw.Draw(rgba, rgba.Bounds(), image.NewUniform(color.Gray16{_16bit_color}), image.Point{}, draw.Src)
draw.Draw(rgba, rgba.Bounds(), image.NewUniform(color), image.Point{}, draw.Src)
return rgba
}

Expand Down
4 changes: 2 additions & 2 deletions draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"golang.org/x/image/math/fixed"
)

func (p *picture) DrawWithColor(_16bit_color uint16, text string) *picture {
func (p *picture) DrawWithColor(color color.RGBA, text string) *picture {
// font color
p.c.SetSrc(image.NewUniform(color.Gray16{_16bit_color}))
p.c.SetSrc(image.NewUniform(color))

face := truetype.NewFace(p.font, &truetype.Options{Size: p.fontSize, DPI: p.dpi})

Expand Down
Binary file modified example/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30f7dd0

Please sign in to comment.