update example 'rotated-image'

This commit is contained in:
wsw 2017-01-08 16:18:14 +08:00
parent b13517ff6f
commit 5e5aa69079
1 changed files with 10 additions and 3 deletions

View File

@ -4,24 +4,31 @@ import "github.com/fogleman/gg"
func main() {
const W = 400
const H = 200
const H = 500
im, err := gg.LoadPNG("examples/gopher.png")
if err != nil {
panic(err)
}
iw, ih := im.Bounds().Dx(), im.Bounds().Dy()
dc := gg.NewContext(W, H)
// draw outline
dc.SetHexColor("#ff0000")
dc.SetLineWidth(1)
dc.DrawRectangle(0, 0, float64(W), float64(H))
dc.Stroke()
// draw full image
dc.SetHexColor("#0000ff")
dc.SetLineWidth(2)
dc.DrawRectangle(100, 210, float64(iw), float64(ih))
dc.Stroke()
dc.DrawImage(im, 100, 210)
// draw image with current matrix applied
dc.SetHexColor("#0000ff")
dc.SetLineWidth(2)
dc.Rotate(gg.Radians(10))
dc.DrawRectangle(100, 0, float64(im.Bounds().Dx()), float64(im.Bounds().Dy())/2)
dc.DrawRectangle(100, 0, float64(iw), float64(ih)/2+20.0)
dc.StrokePreserve()
dc.Clip()
dc.DrawImage(im, 100, 0)
dc.DrawImageAnchored(im, 100, 0, 0.0, 0.0)
dc.SavePNG("out.png")
}