package main
import (
"fmt"
"image"
"image/color"
"image/jpeg"
"os"
"gocv.io/x/gocv"
)
func main() {
height := 50
width := 120
defaultFontScale := 1.
defaultThickness := 1
backgroundColor := color.RGBA{240, 232, 243, 0}
textColor := color.RGBA{108, 58, 98, 255}
brandImage := gocv.NewMatWithSize(height, width, gocv.MatTypeCV8UC3)
defer brandImage.Close()
pointText := image.Point{6, 30}
points := [][]image.Point{
{
image.Pt(0, 0),
image.Pt(width, 0),
image.Pt(width, height),
image.Pt(0, height),
},
}
gocv.Rectangle(&brandImage, image.Rect(0, 50, 120, 50), backgroundColor, defaultThickness)
gocv.FillPoly(&brandImage, points, backgroundColor)
gocv.PutText(&brandImage, "Mijello", pointText, gocv.FontHersheyComplex, defaultFontScale, textColor, defaultThickness)
l, _ := brandImage.ToImage()
f, _ := os.Create("pathToFile/brand.jpg")
err := jpeg.Encode(f, l, nil)
if err != nil {
fmt.Println(err)
}
}
在C
和C#
中,我还有1个参数LineType
,但我不知道如何像这样的示例那样平滑边框:
感谢您的建议。