You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Laurent Le Goff edited this page Apr 19, 2015
·
5 revisions
Draw2d Hello World, initialize a graphic context and save the to a png file.
package main
import (
"bufio""fmt""log""os""github/llgcode/draw2d""image""image/png"
)
funcmain() {
// Create a 200x200 RGBA image img:=image.NewRGBA(image.Rect(0, 0, 200, 200))
// Initialize a graphic context on this imagegc:=draw2d.NewGraphicContext(img)
// Create a new path gc.BeginPath()
// start the path at (10, 10)gc.MoveTo(10.0, 10.0)
// add a lineto the path to (100.0, 10.0)gc.LineTo(100.0, 10.0)
// Strokegc.Stroke()
// Save image to disk filePath:="TestGettingStarted.png"saveToPngFile(filePath, img)
fmt.Printf("Wrote %s OK.\n", filePath)
}
// Save image to a file path using PNG formatfuncsaveToPngFile(filePathstring, m image.Image) error {
// Create the filef, err:=os.Create(filePath)
iferr!=nil {
returnerr
}
deferf.Close()
// Create Writer from fileb:=bufio.NewWriter(f)
// Write the image into the buffererr=png.Encode(b, m)
iferr!=nil {
returnerr
}
err=b.Flush()
iferr!=nil {
returnerr
}
returnnil
}