Is there a way to draw an image by filling one pixel at a time in Golang, preferably using the draw2d package?
For example, one can draw a line by using the stroke() command as such (from their getting started page):
package main
impenter code hereort (
"bufio"
"fmt"
"log"
"os"
"code.google.com/p/draw2d/draw2d"
"image"
"image/png"
)
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.
", filePath)
}
func main() {
i := image.NewRGBA(image.Rect(0, 0, 200, 200))
gc := draw2d.NewGraphicContext(i)
gc.MoveTo(10.0, 10.0)
gc.LineTo(100.0, 10.0)
gc.Stroke()
saveToPngFile("TestPath.png", i)
}
But how could I fill just one pixel, instead of connecting the 2 points? Draw2d is not a necessity, it is simply what I thought would be easiest.