2010-11-25 09:02:53 +00:00
|
|
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
|
|
|
// created: 21/11/2010 by Laurent Le Goff
|
|
|
|
|
2010-11-23 16:37:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"bufio"
|
2010-11-23 18:35:19 +00:00
|
|
|
|
2010-11-23 16:37:21 +00:00
|
|
|
"image"
|
|
|
|
"image/png"
|
2011-03-17 22:32:06 +00:00
|
|
|
"draw2d.googlecode.com/hg/draw2d"
|
2010-11-23 16:37:21 +00:00
|
|
|
)
|
|
|
|
|
2010-11-23 18:35:19 +00:00
|
|
|
|
2010-11-23 16:37:21 +00:00
|
|
|
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)
|
2011-03-20 21:31:54 +00:00
|
|
|
gc := draw2d.NewImageGraphicContext(i)
|
2010-11-23 16:37:21 +00:00
|
|
|
gc.MoveTo(10.0, 10.0)
|
|
|
|
gc.LineTo(100.0, 10.0)
|
|
|
|
gc.Stroke()
|
2010-11-23 18:35:19 +00:00
|
|
|
saveToPngFile("TestPath.png", i)
|
2010-12-06 17:18:39 +00:00
|
|
|
}
|