Exemple #1
0
func test(t *testing.T, draw sample) {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)
	// Draw Android logo
	output, err := draw(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", output, err)
		return
	}
	// Save to png
	err = draw2dimg.SaveToPngFile(output, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", output, err)
	}
}
Exemple #2
0
func TestCircle(t *testing.T) {
	width := 200
	height := 200
	img := image.NewRGBA(image.Rect(0, 0, width, height))
	gc := draw2dimg.NewGraphicContext(img)

	gc.SetStrokeColor(color.NRGBA{255, 255, 255, 255})
	gc.SetFillColor(color.NRGBA{255, 255, 255, 255})
	gc.Clear()

	gc.SetStrokeColor(color.NRGBA{255, 0, 0, 255})
	gc.SetLineWidth(1)

	// Draw a circle
	Circle(gc, 100, 100, 50)
	gc.Stroke()

	draw2dimg.SaveToPngFile("../output/draw2dkit/TestCircle.png", img)
}
Exemple #3
0
func DrawPoint(toilets []models.Toilet, b *models.Bounds, imgWidth int, imgHeight int) string {
	// fmt.Println(imgWidth,imgHeight);
	filename := strconv.Itoa(b.Min.X) + "_" + strconv.Itoa(b.Min.Y)
	filename += "_" + strconv.Itoa(b.Max.X) + "_" + strconv.Itoa(b.Max.Y)
	filename += "_" + strconv.Itoa(imgWidth) + "_" + strconv.Itoa(imgHeight) + ".png"
	HRes := b.GetWidth() / imgWidth
	VRes := b.GetHeight() / imgHeight
	dest := image.NewRGBA(image.Rect(0, 0, imgWidth, imgHeight))
	gc := draw2dimg.NewGraphicContext(dest)
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})

	for _, toilet := range toilets {
		dx := (toilet.Geom.Lng - float64(b.Min.X)) / float64(HRes)                  //x
		dy := float64(imgHeight) - (toilet.Geom.Lat-float64(b.Min.Y))/float64(VRes) //y
		// fmt.Println("toilet :", toilet,dx,dy);
		draw2dkit.Circle(gc, dx, dy, 3)
		gc.FillStroke()
	}
	gc.Close()
	draw2dimg.SaveToPngFile(revel.BasePath+"/output/wms/"+filename, dest)
	return filename
}
Exemple #4
0
// Save the contexts into a final image
func (c *Canvas) Save() {
	draw2dimg.SaveToPngFile(c.filename, c)
}