Golang图片库gg使用示例
示例一
代码如下
package main
import (
"fmt"
"github.com/fogleman/gg"
)
func main() {
const S = 1024
//NewContext调整图片大小
dc := gg.NewContext(S, S)
//图片颜色,有255位彩色,无255位黑白,最后一个参数用来调整颜色深度,0为白色,255位黑色
dc.SetRGBA255(255, 0, 0,30)
for i := 0; i < 360; i += 15 {
dc.Push()
dc.RotateAbout(gg.Radians(float64(i)), S/2, S/2)
//DrawEllipse画椭圆
dc.DrawEllipse(S/2, S/2, S*7/16, S/8)
//DrawRectangle画矩形
//dc.DrawRectangle(S/2, S/2, S*7/16, S/8)
//DrawCircle画圆
//dc.DrawCircle(650,650,130)
dc.Fill()
dc.Pop()
}
err := dc.SavePNG("../../Desktop/ellipse2.png")
if err != nil {
fmt.Println(err)
}
}