draw2d/cmd/gettingStarted.go

46 lines
775 B
Go
Raw Normal View History

2011-04-27 08:06:14 +00:00
// Copyright 2010 The draw2d Authors. All rights reserved.
// created: 21/11/2010 by Laurent Le Goff
package main
import (
2012-01-13 09:14:12 +00:00
"bufio"
2011-04-27 08:06:14 +00:00
"fmt"
2015-04-16 09:51:13 +00:00
"image"
"image/png"
2011-04-27 08:06:14 +00:00
"log"
"os"
"github.com/llgcode/draw2d/draw2d"
2011-04-27 08:06:14 +00:00
)
func saveToPngFile(filePath string, m image.Image) {
f, err := os.Create(filePath)
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() {
2012-01-13 09:14:12 +00:00
i := image.NewRGBA(image.Rect(0, 0, 200, 200))
2011-04-27 08:06:14 +00:00
gc := draw2d.NewGraphicContext(i)
gc.MoveTo(10.0, 10.0)
gc.LineTo(100.0, 10.0)
gc.Stroke()
saveToPngFile("TestPath.png", i)
}