2011-03-24 21:56:53 +00:00
|
|
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
|
|
|
// created: 21/11/2010 by Laurent Le Goff
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"bufio"
|
|
|
|
|
|
|
|
"image"
|
|
|
|
"image/png"
|
|
|
|
"draw2d.googlecode.com/hg/draw2d"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func saveToPngFile(filePath string, m image.Image) {
|
2011-04-20 16:30:48 +00:00
|
|
|
f, err := os.Create(filePath)
|
2011-03-24 21:56:53 +00:00
|
|
|
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)
|
|
|
|
}
|