• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang draw2dimg.SaveToPngFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/llgcode/draw2d/draw2dimg.SaveToPngFile函数的典型用法代码示例。如果您正苦于以下问题:Golang SaveToPngFile函数的具体用法?Golang SaveToPngFile怎么用?Golang SaveToPngFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SaveToPngFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Save

func (p *Canvas) Save() {
	fmt.Println(p.FileName)
	err := dwg.SaveToPngFile(p.FileName, p.Dest)
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:lcaballero,项目名称:img,代码行数:7,代码来源:dwg.go


示例2: TestParseSVG

func TestParseSVG(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping lengthier tests during short test run.")
	}

	var tests = []string{
		"rectfull",
		"rectfullwithtext",
		"tworects",
		"threerects",
	}

	for _, tt := range tests {
		f, err := os.Open("testsvgs/" + tt + ".svg")
		if err != nil {
			t.Errorf("Failed to open %s.svg for reading: %s", tt, err)
			continue
		}
		defer f.Close()

		p := ssvgc.NewParser(f)
		svg, err := p.ParseSVG()
		if err != nil {
			t.Errorf("ParseSVG(%s.svg) failed => %s", tt, err)
			continue
		}

		img := svg.Draw()
		draw2dimg.SaveToPngFile("output/"+tt+".png", img)
	}
}
开发者ID:stephenwithav,项目名称:ssvgc,代码行数:31,代码来源:parser_test.go


示例3: TestImageRendering

func TestImageRendering(t *testing.T) {
	var tests = []StringMap{
		{
			"name": "tuxcentered",
			"xml": `<svg width="200" height="200" fill="white">
<image href="testimages/tux-construction.png" width="150" x="25" y="25" />
</svg>`,
		},
		{
			"name": "tuxbottomright",
			"xml": `<svg width="200" height="200" fill="white">
<image href="testimages/tux-construction.png" width="150" x="50" y="50" />
</svg>`,
		},
		{
			"name": "tuxfullsize",
			"xml": `<svg width="200" height="200" fill="white">
<image href="testimages/tux-construction.png" />
</svg>`,
		},
	}

	for _, tt := range tests {
		r := strings.NewReader(tt["xml"])
		p := ssvgc.NewParser(r)
		svg, err := p.ParseSVG()
		if err != nil {
			t.Errorf("ParseSVG() failed => %s", err)
			continue
		}

		draw2dimg.SaveToPngFile("output/"+tt["name"]+".png", svg.Draw())
	}
}
开发者ID:stephenwithav,项目名称:ssvgc,代码行数:34,代码来源:image_test.go


示例4: DrawClosedLine

// DrawClosedLine draws the line represented by the Points and closes it.
func DrawClosedLine(p Points, width, height float64, name string) {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
	gc := draw2dimg.NewGraphicContext(dest)

	// Set some properties
	gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
	gc.SetLineWidth(5)

	paths := []*draw2d.Path{}

	// Draw a path
	for idx, point := range p[:len(p)] {
		path := new(draw2d.Path)
		path.MoveTo(float64(point.X), height-float64(point.Y))
		if idx < len(p)-1 {
			path.LineTo(float64(p[idx+1].X), height-float64(p[idx+1].Y))
		} else {
			path.LineTo(float64(p[0].X), height-float64(p[0].Y))
		}
		paths = append(paths, path)
	}
	gc.Stroke(paths...)
	gc.FillStroke()

	// Save to file
	draw2dimg.SaveToPngFile(name, dest)
}
开发者ID:caneroj1,项目名称:geometry,代码行数:29,代码来源:draw.go


示例5: TestFreetypeRasterizerNonZeroWinding

func TestFreetypeRasterizerNonZeroWinding(t *testing.T) {
	var p Path
	p.LineTo(10, 190)
	draw2dbase.TraceCubic(&p, []float64{10, 190, 10, 10, 190, 10, 190, 190}, 0.5)
	poly := Polygon(p.points)
	color := color.RGBA{0, 0, 0, 0xff}

	img := image.NewRGBA(image.Rect(0, 0, 200, 200))
	rasterizer := raster.NewRasterizer(200, 200)
	rasterizer.UseNonZeroWinding = true
	rasterizer.Start(raster.Point{
		X: raster.Fix32(10 * 256),
		Y: raster.Fix32(190 * 256)})
	for j := 0; j < len(poly); j = j + 2 {
		rasterizer.Add1(raster.Point{
			X: raster.Fix32(poly[j] * 256),
			Y: raster.Fix32(poly[j+1] * 256)})
	}
	painter := raster.NewRGBAPainter(img)
	painter.SetColor(color)
	rasterizer.Rasterize(painter)

	err := draw2dimg.SaveToPngFile("output/TestFreetypeRasterizerNonZeroWinding.png", img)
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:llgcode,项目名称:go-exp-raster,代码行数:27,代码来源:raster_test.go


示例6: DrawAdjustedToFile

func (r *Renderer) DrawAdjustedToFile(filename string) error {
	dest := r.Draw()
	if subimage, ok := dest.(SubImage); ok {
		bb := r.bbox
		x0, y0, x1, y1 := int(bb[0]), int(bb[1]), int(bb[2]), int(bb[3])
		dest = subimage.SubImage(image.Rect(x0, y0, x1, y1))
	}
	return draw2dimg.SaveToPngFile(filename, dest)
}
开发者ID:samlecuyer,项目名称:ecumene,代码行数:9,代码来源:renderer.go


示例7: mainDrawOne

func mainDrawOne(filename string, space hilbert.SpaceFilling) error {
	log.Printf("Drawing one image %q", filename)

	img, err := createSpaceFillingImage(space, 64, 64).Draw()
	if err != nil {
		return err
	}
	return draw2dimg.SaveToPngFile(filename, img)
}
开发者ID:google,项目名称:hilbert,代码行数:9,代码来源:demo.go


示例8: main

func main() {

	pl := NewPlotter(200, 1000)

	pl.Plot([]Point{{1, 2}, {2, 4}, {3, 2}, {4, 3}})
	pl.Plot([]Point{{10, 40}, {20, 10}, {30, 20}, {40, 30}})
	pl.Plot(Sine(20))

	// Save to file
	draw2dimg.SaveToPngFile("hello.png", pl.image)
}
开发者ID:taysom,项目名称:va,代码行数:11,代码来源:dr.go


示例9: main

func main() {
	i := image.NewRGBA(image.Rect(0, 0, 200, 200))
	gc := draw2dimg.NewGraphicContext(i)
	gc.Save()
	gc.SetStrokeColor(color.Black)
	gc.SetFillColor(color.Black)
	draw2d.Rect(gc, 10, 10, 100, 100)
	gc.FillStroke()
	gc.Restore()

	draw2dimg.SaveToPngFile("yay-rectangle.png", i)
}
开发者ID:walrus7521,项目名称:code,代码行数:12,代码来源:draw.go


示例10: DrawTest

func DrawTest() {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)

	DrawHello(gc, "Hello World")

	// Save to png
	err := draw2dimg.SaveToPngFile("_testHello.png", dest)
	if err != nil {
		log.Fatalln("Saving failed:", err)
	}
}
开发者ID:Kimau,项目名称:GoDriveTracker,代码行数:13,代码来源:main_test.go


示例11: Test

func Test(t *testing.T) {
	dest := image.NewRGBA(image.Rect(0, 0, 300, 300))
	renderer := NewImageRenderer(dest)
	hash := string(md5.New().Sum([]byte("Jeremiah")))
	config := Config{}
	identicon, err := NewIconGenerator(renderer, hash, 0, 0, 300, 8, config)
	if err != nil {
		t.Error(err)
	}
	identicon.Generator()
	draw2dimg.SaveToPngFile("./test.png", dest)

}
开发者ID:truyet,项目名称:go,代码行数:13,代码来源:test.go


示例12: TestRectangleDrawing

func TestRectangleDrawing(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping lengthier tests during short test run.")
	}

	var tests = []StringMap{
		{
			"name":   "solidblue",
			"fill":   "blue",
			"width":  "400",
			"height": "400",
		},
		{
			"name":         "redinsetwithblue",
			"fill":         "blue",
			"stroke":       "red",
			"stroke-width": "30",
			"width":        "400",
			"height":       "400",
		},
		{
			"name":         "redinsetwithblue2",
			"fill":         "blue",
			"stroke":       "red",
			"stroke-width": "1",
			"width":        "400",
			"height":       "400",
		},
		{
			"name":         "solidredstrokedgreen",
			"fill":         "red",
			"width":        "100",
			"height":       "100",
			"x":            "50",
			"y":            "50",
			"stroke":       "green",
			"stroke-width": "15",
		},
	}

	for _, tt := range tests {
		r := ssvgc.NewRectangle()
		for name, value := range tt {
			r.SetAttribute(name, value)
		}

		draw2dimg.SaveToPngFile("output/"+tt["name"]+".png", r.Draw())
	}
}
开发者ID:stephenwithav,项目名称:ssvgc,代码行数:49,代码来源:rectangle_test.go


示例13: TestRasterizerNonZeroWinding

func TestRasterizerNonZeroWinding(t *testing.T) {
	img := image.NewRGBA(image.Rect(0, 0, 200, 200))
	var p Path
	p.LineTo(10, 190)
	draw2dbase.TraceCubic(&p, []float64{10, 190, 10, 10, 190, 10, 190, 190}, 0.5)

	poly := Polygon(p.points)
	color := color.RGBA{0, 0, 0, 0xff}
	tr := [6]float64{1, 0, 0, 1, 0, 0}
	r := NewRasterizer8BitsSample(200, 200)
	//PolylineBresenham(img, image.Black, poly...)

	r.RenderNonZeroWinding(img, &color, &poly, tr)
	draw2dimg.SaveToPngFile("../output/raster/TestRasterizerNonZeroWinding.png", img)
}
开发者ID:Wayt,项目名称:draw2d,代码行数:15,代码来源:raster_test.go


示例14: compile

func compile(frdat string, fnum int) error {
	r := strings.NewReader(frdat)

	fr, rerr := ani.ReadFrame(r)
	if rerr != nil {
		return fmt.Errorf("Error reading frame %v: %v\nFrame follows\n%v\n",
			fnum, rerr, frdat)
	}

	img := render(fr, fnum)

	fname := fmt.Sprintf("%06d.png", fnum)
	err := dimg.SaveToPngFile(fname, img)

	return err
}
开发者ID:johnny-morrice,项目名称:amoebethics,代码行数:16,代码来源:amoerender.go


示例15: test

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)
	}
}
开发者ID:zzn01,项目名称:draw2d,代码行数:16,代码来源:test_test.go


示例16: main

func main() {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 1300, 1200))
	gc := draw2dimg.NewGraphicContext(dest)
	gb := draw2dimg.NewGraphicContext(dest)

	n := draw2d.NewRotationMatrix(math.Pi / 2)
	n.Translate(100, -100)
	gb.SetMatrixTransform(n)
	Draw(gb, "My Text")
	// Set some properties
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
	gc.SetLineWidth(3)

	m := draw2d.NewRotationMatrix(-0.3)
	//	m.TransformRectangle(40, 40, 100, 500)
	m.Translate(75, 75)
	gc.SetMatrixTransform(m)

	// Draw a closed shape
	gc.MoveTo(39, 39) // should always be called first for a new path
	gc.LineTo(39, 512)
	gc.LineTo(512, 512)
	gc.LineTo(512, 39)
	gc.LineTo(39, 39)
	//gc.LineTo(100, 50)
	//gc.QuadCurveTo(100, 10, 10, 10)
	gc.Close()
	gc.FillStroke()

	gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, 0x77})
	gc.SetMatrixTransform(draw2d.NewRotationMatrix(0))
	gc.MoveTo(47, 47) // should always be called first for a new path
	gc.LineTo(47, 617)
	gc.LineTo(617, 617)
	gc.LineTo(617, 47)
	gc.LineTo(47, 47)
	gc.Close()
	gc.FillStroke()

	g1 := []Point{{1, 2}, {2, 3}, {3, 4}, {4, 3}}
	Plot(gb, g1)

	// Save to file
	draw2dimg.SaveToPngFile("hello.png", dest)
}
开发者ID:taysom,项目名称:va,代码行数:47,代码来源:2d.go


示例17: TestRasterizerNonZeroWinding

func TestRasterizerNonZeroWinding(t *testing.T) {
	bounds := image.Rect(0, 0, 200, 200)
	img := image.NewRGBA(bounds)
	mask := image.NewAlpha(bounds)
	var p Path
	p.LineTo(10, 190)
	draw2dbase.TraceCubic(&p, []float64{10, 190, 10, 10, 190, 10, 190, 190}, 0.5)
	poly := Polygon(p.points)
	rgba := color.RGBA{0, 0, 0, 0xff}
	r := NewRasterizer()
	r.Fill(mask, poly, true)
	DrawSolidRGBA(img, mask, rgba)
	err := draw2dimg.SaveToPngFile("output/TestRasterizerNonZeroWinding.png", img)
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:llgcode,项目名称:go-exp-raster,代码行数:17,代码来源:raster_test.go


示例18: TestCircle

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)
}
开发者ID:zzn01,项目名称:draw2d,代码行数:19,代码来源:draw2dkit_test.go


示例19: main

func main() {

	file, err := os.Open("img/test.svg")

	check(err)

	defer file.Close()

	size := image.Point{1000, 1000}

	dest, err := svg.Render(file, size)

	check(err)

	err = draw2dimg.SaveToPngFile("/home/test.png", dest)

	check(err)

	fmt.Println("done")
}
开发者ID:sinistersig,项目名称:svg-png-go,代码行数:20,代码来源:main.go


示例20: DrawPolygon

// DrawPolygon draws the polygon represented by Points on the canvas
func DrawPolygon(p Points, width, height float64, name string) {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
	gc := draw2dimg.NewGraphicContext(dest)

	// Set some properties
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
	gc.SetLineWidth(5)

	// Draw a closed shape
	gc.MoveTo(float64(p[0].X), height-float64(p[0].Y))
	for _, point := range p[1:] {
		gc.LineTo(float64(point.X), height-float64(point.Y))
		gc.MoveTo(float64(point.X), height-float64(point.Y))
	}
	gc.Close()
	gc.FillStroke()

	// Save to file
	draw2dimg.SaveToPngFile(name, dest)
}
开发者ID:caneroj1,项目名称:geometry,代码行数:23,代码来源:draw.go



注:本文中的github.com/llgcode/draw2d/draw2dimg.SaveToPngFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.Equal函数代码示例发布时间:2022-05-23
下一篇:
Golang draw2dimg.NewGraphicContext函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap