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

Golang draw2dimg.NewGraphicContext函数代码示例

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

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



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

示例1: Load

// Load an image from a PNG file
func Load(path string) (*Image, error) {
	var img Image

	file, err := os.Open(path)
	if err != nil {
		fmt.Println("ERROR: Cannot open file", path)
		return nil, err
	}

	defer func() {
		if err := file.Close(); err != nil {
			panic(err)
		}
	}()

	pngImage, err := png.Decode(file)
	if err != nil {
		fmt.Println("ERROR: Cannot decode PNG file", path)
		return nil, err
	}

	// Copy to surface
	b := pngImage.Bounds()
	img.Surf = image.NewRGBA(image.Rect(0, 0, b.Max.X-b.Min.X, b.Max.Y-b.Min.Y))
	draw.Draw(img.Surf, img.Surf.Bounds(), pngImage, pngImage.Bounds().Min, draw.Src)

	img.Ctx = draw2dimg.NewGraphicContext(img.Surf)
	br := img.Surf.Bounds()
	img.W, img.H = br.Max.X-br.Min.X, br.Max.Y-br.Min.Y

	return &img, nil
}
开发者ID:akiross,项目名称:gogp,代码行数:33,代码来源:imgops.go


示例2: 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


示例3: faceDetect

func faceDetect(settings CropSettings, i image.Image, o image.Image) error {

	cvImage := opencv.FromImage(i)
	_, err := os.Stat(settings.FaceDetectionHaarCascadeFilepath)
	if err != nil {
		return err
	}
	cascade := opencv.LoadHaarClassifierCascade(settings.FaceDetectionHaarCascadeFilepath)
	faces := cascade.DetectObjects(cvImage)

	gc := draw2dimg.NewGraphicContext((o).(*image.RGBA))

	if settings.DebugMode == true {
		log.Println("Faces detected:", len(faces))
	}

	for _, face := range faces {
		if settings.DebugMode == true {
			log.Printf("Face: x: %d y: %d w: %d h: %d\n", face.X(), face.Y(), face.Width(), face.Height())
		}
		draw2dkit.Ellipse(
			gc,
			float64(face.X()+(face.Width()/2)),
			float64(face.Y()+(face.Height()/2)),
			float64(face.Width()/2),
			float64(face.Height())/2)
		gc.SetFillColor(color.RGBA{255, 0, 0, 255})
		gc.Fill()
	}
	return nil
}
开发者ID:dexter-cn,项目名称:smartcrop,代码行数:31,代码来源:crop.go


示例4: render

func render(fr ani.Frame, fnum int) image.Image {
	w, h := fr.SurfaceDims()

	// Blank white image
	bounds := image.Rect(0, 0, int(w), int(h))
	dest := image.NewRGBA(bounds)
	draw.Draw(dest, bounds, &image.Uniform{white}, image.ZP, draw.Src)

	shapes := []string{
		"circle",
		"square",
	}
	plts := []plot{}

	for _, sh := range shapes {
		plts = append(plts, plotShape(sh, fr))
	}

	plts = append(plts, plotExplode(fr))

	gc := dimg.NewGraphicContext(dest)

	gc.SetStrokeColor(black)
	gc.SetFillColor(black)

	for _, plot := range plts {
		plot.draw(gc)
	}

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


示例5: newImg

func newImg(filename string, w, h, levels int) img {
	// Leave a 5% buffer on the sides so that the image doesn't cut right up to
	// the edge
	bw, bh := float64(w)*0.95, float64(h)*0.95
	var levelWidth float64
	if w > h {
		levelWidth = bh / 2 / float64(levels)
	} else {
		levelWidth = bw / 2 / float64(levels)
	}

	if levelWidth < 1 {
		log.Fatalf("level width is too small! %f", levelWidth)
	}

	rgba := image.NewRGBA(image.Rect(0, 0, w, h))
	ctx := draw2dimg.NewGraphicContext(rgba)

	return img{
		filename:   filename,
		w:          w,
		h:          h,
		centerX:    float64(w) / 2,
		centerY:    float64(h) / 2,
		levelWidth: int(levelWidth),
		rgba:       rgba,
		ctx:        ctx,
	}
}
开发者ID:mediocregopher,项目名称:happy-tree,代码行数:29,代码来源:draw.go


示例6: drawLines

func drawLines(src image.Image, lines []polarLine) image.Image {
	dst := image.NewRGBA(src.Bounds())

	gc := draw2dimg.NewGraphicContext(dst)
	gc.SetFillColor(color.RGBA{0x0, 0x0, 0x0, 0xff})
	gc.SetStrokeColor(color.RGBA{0x0, 0xff, 0x0, 0xff})
	gc.SetLineWidth(2)
	gc.Clear()
	gc.DrawImage(src)

	for _, line := range lines {
		a := math.Cos(line.Theta)
		b := math.Sin(line.Theta)
		x0 := a * float64(line.Distance)
		y0 := b * float64(line.Distance)
		x1 := (x0 + 10000*(-b))
		y1 := (y0 + 10000*(a))
		x2 := (x0 - 10000*(-b))
		y2 := (y0 - 10000*(a))

		gc.MoveTo(x1, y1)
		gc.LineTo(x2, y2)
		gc.Close()
	}

	gc.FillStroke()
	return dst
}
开发者ID:mrfuxi,项目名称:sudoku,代码行数:28,代码来源:visualize.go


示例7: Create

// Create an image of the given size
func Create(w, h int, mode ColorSpace) *Image {
	var img Image
	img.Surf = image.NewRGBA(image.Rect(0, 0, w, h))
	img.Ctx = draw2dimg.NewGraphicContext(img.Surf)
	img.W, img.H = w, h
	return &img
}
开发者ID:akiross,项目名称:gogp,代码行数:8,代码来源:imgops.go


示例8: 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


示例9: NewCanvas

func NewCanvas(c *Canvas) *Canvas {
	dest := image.NewRGBA(c.Rect())
	ctx := dwg.NewGraphicContext(dest)

	c.Dest = dest
	c.GraphicContext = ctx
	return c
}
开发者ID:lcaballero,项目名称:img,代码行数:8,代码来源:dwg.go


示例10: NewContext

func NewContext() *Context {
	img := image.NewRGBA(image.Rect(0, 0, 640, 360))
	ctx := &Context{
		img,
		draw2dimg.NewGraphicContext(img),
		StyleDefault,
	}
	ctx.SetFontData(draw2d.FontData{Name: "Default"})

	return ctx
}
开发者ID:sarifsystems,项目名称:sarif,代码行数:11,代码来源:renderer.go


示例11: Draw

func (r *Renderer) Draw() image.Image {
	pixelsX, pixelsY := int(r.width), int(r.height)

	dest := image.NewRGBA(image.Rect(0, 0, pixelsX, pixelsY))
	draw.Draw(dest, dest.Bounds(), &image.Uniform{r.m.BgColor}, image.ZP, draw.Src)

	draw2d.SetFontFolder("/Library/Fonts/")
	draw2d.SetFontNamer(func(fontData draw2d.FontData) string {
		return fontData.Name + ".ttf"
	})
	gc := draw2dimg.NewGraphicContext(dest)
	// gc.DPI = 300

	gc.SetLineCap(draw2d.RoundCap)
	gc.SetFillColor(r.m.BgColor)
	gc.SetStrokeColor(r.m.Stroke)
	gc.SetFontData(draw2d.FontData{Name: "Georgia", Family: draw2d.FontFamilySerif, Style: draw2d.FontStyleNormal})

	dx := math.Abs(r.bbox[2] - r.bbox[0])
	dy := math.Abs(r.bbox[3] - r.bbox[1])

	pxf, pyf := float64(pixelsX), float64(pixelsY)
	r1, r2 := (pxf / dx), (pyf / dy)
	r0 := math.Min(r1, r2)
	w, h := dx*r0, dy*r0
	ox, oy := (pxf-w)/2, (pyf-h)/2
	img_box := [4]float64{ox, oy, ox + w, oy + h}

	r.matrix = draw2d.NewMatrixFromRects(r.bbox, img_box)

	for _, layer := range r.m.Layers {
		q := query.NewQuery(r.m.Bounds()).Select(layer.SourceQuery())
		if ds := layer.LoadSource(); ds != nil {
			defer ds.Close()
			for shp := range ds.Query(q) {
				var symbolizerType util.SymbolizerType
				switch shp.(type) {
				case geom.LineShape, geom.MultiLineShape:
					symbolizerType = util.PathType
				case geom.PolygonShape:
					symbolizerType = util.PolygonType
				}
				for _, symbolizer := range r.findSymbolizers(layer, symbolizerType) {
					symbolizer.Draw(gc, shp)
				}
				for _, symbolizer := range r.findSymbolizers(layer, util.TextType) {
					symbolizer.Draw(gc, shp)
				}
			}
		}
	}

	return dest
}
开发者ID:samlecuyer,项目名称:ecumene,代码行数:54,代码来源:renderer.go


示例12: NewPlotter

func NewPlotter(height, width float64) *Plotter {
	pl := Plotter{lineWidth: 3, height: height, width: width, border: 10, xSteps: 10, ySteps: 5}

	pl.image = image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
	pl.g = draw2dimg.NewGraphicContext(pl.image)

	// Set some properties
	pl.g.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	pl.g.SetStrokeColor(color.Black)
	return &pl
}
开发者ID:taysom,项目名称:va,代码行数:11,代码来源:dr.go


示例13: 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


示例14: 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


示例15: drawPolyLine

func drawPolyLine(img *image.RGBA, color color.Color, coords [][]float64) {
	path := new(draw2d.Path)
	for i, coord := range coords {
		if i == 0 {
			path.MoveTo(coord[0], coord[1])
		} else {
			path.LineTo(coord[0], coord[1])
		}
	}

	gc := draw2dimg.NewGraphicContext(img)
	gc.SetStrokeColor(color)
	gc.Stroke(path)
}
开发者ID:Ganners,项目名称:go-tile-server,代码行数:14,代码来源:draw.go


示例16: GenerateImage

func GenerateImage(size int, cube gocube.StickerCube) image.Image {
	dest := image.NewRGBA(image.Rect(0, 0, size, size))
	ctx := draw2dimg.NewGraphicContext(dest)

	scale := float64(size) / 500
	ctx.Scale(-1, 1)
	ctx.Translate(-float64(size), 0)

	drawBackground(ctx, scale)
	drawTopFace(ctx, scale, mirrorDiagonally(colorsForStickers(cube[:9])))
	drawRightFace(ctx, scale, mirrorHorizontally(colorsForStickers(cube[9*4:9*5])))
	drawFrontFace(ctx, scale, mirrorHorizontally(colorsForStickers(cube[9*2:9*3])))

	return dest
}
开发者ID:unixpickle,项目名称:rubiksimg,代码行数:15,代码来源:api.go


示例17: 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


示例18: AddTo

// AddTo returns a new ImageGraphics which will write to (width x height) sized
// area starting at (x,y) on the provided image img. The rest of the parameters
// are the same as in New().
func AddTo(img *image.RGBA, x, y, width, height int, bgcol color.RGBA, font *truetype.Font, fontsize map[chart.FontSize]float64) *ImageGraphics {
	gc := draw2dimg.NewGraphicContext(img)
	gc.SetLineJoin(draw2d.BevelJoin)
	gc.SetLineCap(draw2d.SquareCap)
	gc.SetStrokeColor(image.Black)
	gc.SetFillColor(bgcol)
	gc.Translate(float64(x)+0.5, float64(y)+0.5)
	gc.ClearRect(x, y, x+width, y+height)
	if font == nil {
		font = defaultFont
	}
	if len(fontsize) == 0 {
		fontsize = ConstructFontSizes(13)
	}

	return &ImageGraphics{Image: img, x0: x, y0: y, w: width, h: height, bg: bgcol, gc: gc, font: font, fs: fontsize}
}
开发者ID:RobinTec,项目名称:chart,代码行数:20,代码来源:image.go


示例19: imgPng

func imgPng(w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-type", "image/png")

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

	// Draw sample
	android.Draw(gc, 65, 0)

	err := png.Encode(w, dest)
	if err != nil {
		return &appError{err, fmt.Sprintf("Can't encode: %s", err), 500}
	}

	return nil
}
开发者ID:zzn01,项目名称:draw2d,代码行数:17,代码来源:server.go


示例20: GenerateCaptionedImage

func GenerateCaptionedImage(size int, fontSize float64, caption string,
	cube gocube.StickerCube) image.Image {
	dest := image.NewRGBA(image.Rect(0, 0, size, size))
	ctx := draw2dimg.NewGraphicContext(dest)

	captionImage := generateCaptionImage(size, fontSize, caption)
	captionHeight := float64(captionImage.Bounds().Dy())
	remainingSize := float64(size) - captionHeight

	ctx.DrawImage(captionImage)

	cubeImage := GenerateImage(int(remainingSize), cube)
	ctx.Translate((float64(size)-remainingSize)/2, captionHeight)
	ctx.DrawImage(cubeImage)

	return dest
}
开发者ID:unixpickle,项目名称:rubiksimg,代码行数:17,代码来源:api.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang draw2dimg.SaveToPngFile函数代码示例发布时间:2022-05-23
下一篇:
Golang curve.CubicCurveFloat64类代码示例发布时间: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