From 66148a5bf98e7c0e2118b9f6252611da9a7f5445 Mon Sep 17 00:00:00 2001 From: "legoff.laurent" Date: Tue, 23 Nov 2010 16:37:21 +0000 Subject: [PATCH] test getting started --- draw2d/src/cmd/gettingStarted.go | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 draw2d/src/cmd/gettingStarted.go diff --git a/draw2d/src/cmd/gettingStarted.go b/draw2d/src/cmd/gettingStarted.go new file mode 100644 index 0000000..ef6762d --- /dev/null +++ b/draw2d/src/cmd/gettingStarted.go @@ -0,0 +1,44 @@ +package main + + +import ( + "fmt" + "log" + "os" + "bufio" + + "image" + "image/png" + "draw2d" +) + +func saveToPngFile(filePath string, m image.Image) { + f, err := os.Open(filePath, os.O_CREAT|os.O_WRONLY, 0600) + if err != nil { + log.Println(err) + os.Exit(1) + } + defer f.Close() + b := bufio.NewWriter(f) + err = png.Encode(b, m) + if err != nil { + log.Println(err) + os.Exit(1) + } + err = b.Flush() + if err != nil { + log.Println(err) + os.Exit(1) + } + fmt.Printf("Wrote %s OK.\n", filePath) +} + +func main() { + i := image.NewRGBA(200, 200) + gc := draw2d.NewGraphicContext(i) + gc.MoveTo(10.0, 10.0) + gc.LineTo(100.0, 10.0) + gc.Stroke() + + saveToPngFile("../../TestPath.png", i) +}