當前位置: 首頁>>代碼示例>>Golang>>正文


Golang draw2d.NewGraphicContext函數代碼示例

本文整理匯總了Golang中code/google/com/p/draw2d/draw2d.NewGraphicContext函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewGraphicContext函數的具體用法?Golang NewGraphicContext怎麽用?Golang NewGraphicContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewGraphicContext函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: faceDetect

func faceDetect(i *image.Image, o *image.Image) {

	cvImage := opencv.FromImage(*i)
	_, err := os.Stat(faceDetectionHaarCascade)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	cascade := opencv.LoadHaarClassifierCascade(faceDetectionHaarCascade)
	faces := cascade.DetectObjects(cvImage)

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

	if debug == true {
		fmt.Println("Faces detected:", len(faces))
	}

	for _, face := range faces {
		if debug == true {
			fmt.Printf("Face: x: %d y: %d w: %d h: %d\n", face.X(), face.Y(), face.Width(), face.Height())
		}
		draw2d.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()
	}

}
開發者ID:Bob5435,項目名稱:smartcrop,代碼行數:32,代碼來源:crop.go

示例2: newContext

func newContext(w, h int) (image.Image, draw2d.GraphicContext) {
	m := image.NewRGBA(image.Rect(0, 0, w, h))
	ctxt := draw2d.NewGraphicContext(m)
	ctxt.SetFillColor(image.White)
	ctxt.SetStrokeColor(image.Black)
	return m, ctxt
}
開發者ID:upstartmobile,項目名稱:gogeos,代碼行數:7,代碼來源:examples.go

示例3: textImage

func (c *Canvas) textImage(font vg.Font, str string) *image.RGBA {
	w := font.Width(str).Dots(c)
	h := font.Extents().Height.Dots(c)
	img := image.NewRGBA(image.Rect(0, 0, int(w+0.5), int(h+0.5)))
	gc := draw2d.NewGraphicContext(img)

	gc.SetDPI(int(c.DPI()))
	gc.SetFillColor(c.color[len(c.color)-1])
	gc.SetStrokeColor(c.color[len(c.color)-1])
	data, ok := fontMap[font.Name()]
	if !ok {
		panic(fmt.Sprintf("Font name %s is unknown", font.Name()))
	}

	if !registeredFont[font.Name()] {
		draw2d.RegisterFont(data, font.Font())
		registeredFont[font.Name()] = true
	}

	gc.SetFontData(data)
	gc.SetFontSize(font.Size.Points())
	gc.MoveTo(0, h+font.Extents().Descent.Dots(c))
	gc.FillString(str)

	return img
}
開發者ID:vron,項目名稱:plotinum,代碼行數:26,代碼來源:vgimg.go

示例4: drawImage

func (k *Karta) drawImage() {
	img := image.NewRGBA(image.Rect(0, 0, k.Width, k.Height))

	l := draw2d.NewGraphicContext(img)

	l.SetLineWidth(1.2)

	// Iterate over cells
	for i, cell := range k.Diagram.Cells {
		l.SetFillColor(k.Cells[i].FillColor)
		l.SetStrokeColor(k.Cells[i].StrokeColor)

		for _, hedge := range cell.Halfedges {
			a := hedge.GetStartpoint()
			b := hedge.GetEndpoint()

			l.MoveTo(a.X, a.Y)
			l.LineTo(b.X, b.Y)
		}

		l.FillStroke()
	}

	l.Close()

	k.Image = img
}
開發者ID:stanim,項目名稱:karta,代碼行數:27,代碼來源:generate.go

示例5: RenderString

func RenderString(text string, fd draw2d.FontData, size float64, color color.Color) (buffer image.Image) {

	const stretchFactor = 1.2

	height := GetFontHeight(fd, size) * stretchFactor
	widthMax := float64(len(text)) * size

	buf := image.NewRGBA(image.Rectangle{
		Min: image.Point{0, 0},
		Max: image.Point{int(widthMax + 1), int(height + 1)},
	})

	gc := draw2d.NewGraphicContext(buf)
	gc.Translate(0, height/stretchFactor)
	gc.SetFontData(fd)
	gc.SetFontSize(size)
	gc.SetStrokeColor(color)
	width := gc.FillString(text)

	buffer = buf.SubImage(image.Rectangle{
		Min: image.Point{0, 0},
		Max: image.Point{int(width + 1), int(height + 1)},
	})

	return
}
開發者ID:npalumbo,項目名稱:go.uik,代碼行數:26,代碼來源:fonts.go

示例6: line

func line(i *image.RGBA, x, y, x0, y0 int) {
	gc := draw2d.NewGraphicContext(i)
	gc.SetStrokeColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
	gc.MoveTo(float64(x), float64(y))
	gc.LineTo(float64(x0), float64(y0))
	gc.Stroke()
}
開發者ID:karlek,項目名稱:libra,代碼行數:7,代碼來源:libra.go

示例7: drawImage

func drawImage(bmp image.Image, state *DrawingState) image.Image {
	result := image.NewRGBA(bmp.Bounds())
	draw.Draw(result, result.Bounds(), image.Black, image.ZP, draw.Src)

	g := draw2d.NewGraphicContext(result)
	g.SetStrokeColor(color.White)
	g.SetLineWidth(1)

	const maxIterations = 1000000
	var newState *DrawingState
	for i := 0; i < maxIterations; i++ {
		newState = Next(bmp, state)

		if newState == nil {
			break
		}

		g.MoveTo(float64(state.P.X), float64(state.P.Y))
		if newState.Clr != 0 {
			g.LineTo(float64(newState.P.X), float64(newState.P.Y))
			g.Stroke()
		}

		state = newState
	}

	return result
}
開發者ID:dfyz,項目名稱:thedeemon-contest,代碼行數:28,代碼來源:fidonet_cracker.go

示例8: Draw

func (f *Foundation) Draw(buffer draw.Image, invalidRects RectSet) {
	gc := draw2d.NewGraphicContext(buffer)
	f.DoPaint(gc)
	for child, bounds := range f.getChildBoundsMap() {
		r := RectangleForRect(bounds)

		// only redraw those that have been invalidated or are
		// otherwise unable to draw themselves
		if child.buffer == nil || invalidRects.Intersects(bounds) {

			subInv := invalidRects.Intersection(bounds).Translate(bounds.Min.Times(-1))
			or := image.Rectangle{
				Max: image.Point{int(child.Size.X), int(child.Size.Y)},
			}
			if child.buffer == nil || child.buffer.Bounds() != or {
				child.buffer = image.NewRGBA(or)
			} else {
				for _, r := range subInv {
					ir := RectangleForRect(r)
					ZeroRGBA(child.buffer.(*image.RGBA).SubImage(ir).(*image.RGBA))
				}
			}

			subInv = subInv.Translate(bounds.Min.Times(-1))

			child.Drawer.Draw(child.buffer, subInv)
		}

		draw.Draw(buffer, r, child.buffer, image.Point{0, 0}, f.DrawOp)
	}
}
開發者ID:sebastianskejoe,項目名稱:go.uik,代碼行數:31,代碼來源:foundation.go

示例9: handleWindowDrawing

func (wf *WindowFoundation) handleWindowDrawing() {
	// TODO: collect a dirty region (possibly disjoint), and draw in one go?
	wf.ParentDrawBuffer = make(chan image.Image)

	for {
		select {
		case dirtyBounds := <-wf.Redraw:
			gc := draw2d.NewGraphicContext(wf.W.Screen())
			gc.Clear()
			gc.BeginPath()
			// TODO: pass dirtyBounds too, to avoid redrawing out of reach components
			_ = dirtyBounds
			wf.doPaint(gc)

			dr := DrawRequest{
				Dirty: dirtyBounds,
			}
			wf.Draw <- dr

			wf.W.FlushImage()
		case buffer := <-wf.ParentDrawBuffer:
			draw.Draw(wf.W.Screen(), buffer.Bounds(), buffer, image.Point{0, 0}, draw.Src)
			// TODO: don't do this every time - give a window for all expected buffers to
			//       come in before flushing prematurely
			wf.W.FlushImage()
		}
	}
}
開發者ID:ajstarks,項目名稱:go.uik,代碼行數:28,代碼來源:wfound.go

示例10: Render

func (p *GesturePane) Render() (*image.RGBA, error) {
	img := image.NewRGBA(image.Rect(0, 0, 16, 16))

	if p.last != nil {

		x := math.Floor(float64(p.last.Position.X)/float64(0xffff)*float64(16)) + 0.5
		y := math.Floor(float64(p.last.Position.Y)/float64(0xffff)*float64(16)) + 0.5
		z := math.Floor(float64(p.last.Position.Z)/float64(0xffff)*float64(16)) + 0.5

		r, _ := colorful.Hex("#FF000")
		g, _ := colorful.Hex("#00FF00")
		b, _ := colorful.Hex("#0000FF")

		gc := draw2d.NewGraphicContext(img)

		gc.SetStrokeColor(r)
		gc.MoveTo(0, x)
		gc.LineTo(16, x)
		gc.Stroke()

		gc.SetStrokeColor(g)
		gc.MoveTo(y, 0)
		gc.LineTo(y, 16)
		gc.Stroke()

		gc.SetStrokeColor(b)
		gc.MoveTo(16-z, 0)
		gc.LineTo(16-z, 16)
		gc.Stroke()
	}

	return img, nil
}
開發者ID:lindsaymarkward,項目名稱:sphere-go-led-controller,代碼行數:33,代碼來源:GesturePane.go

示例11: render

func (e *Entry) render() {
	const stretchFactor = 1.2

	text := string(e.text)

	height := uik.GetFontHeight(e.fd, e.fontSize) * stretchFactor
	widthMax := float64(len(text)) * e.fontSize

	buf := image.NewRGBA(image.Rectangle{
		Min: image.Point{0, 0},
		Max: image.Point{int(widthMax + 1), int(height + 1)},
	})

	gc := draw2d.NewGraphicContext(buf)
	gc.Translate(0, height/stretchFactor)
	gc.SetFontData(e.fd)
	gc.SetFontSize(e.fontSize)
	gc.SetStrokeColor(color.Black)

	var left float64
	e.runeOffsets = []float64{0}
	for _, r := range e.text {
		rt := string(r)
		width := gc.FillString(rt)
		gc.Translate(width, 0)
		left += width
		e.runeOffsets = append(e.runeOffsets, left)
	}

	e.textBuffer = buf.SubImage(image.Rectangle{
		Min: image.Point{0, 0},
		Max: image.Point{int(left + 1), int(height + 1)},
	}).(*image.RGBA)
}
開發者ID:Nightgunner5,項目名稱:go.uik,代碼行數:34,代碼來源:entry.go

示例12: GetTheImageGraphicContext

// Gets the singleton ImageGraphicContext.
func GetTheImageGraphicContext() *draw2d.ImageGraphicContext {
	if graphicContextInstance == nil {
		graphicContextInstance = draw2d.NewGraphicContext(GetTheImage().canvas)
	}

	return graphicContextInstance
}
開發者ID:GeorgiPetkov,項目名稱:draw2dAnimation,代碼行數:8,代碼來源:imageAndGraphicContextSingletons.go

示例13: Draw

func Draw(r *td6.Ride) image.Image {
	width := PIECE_WIDTH * (len(r.TrackData.Elements) + 2)
	rect := image.Rect(0, 0, width, IMG_HEIGHT)
	i := image.NewRGBA(rect)
	c := color.RGBA{0xff, 0xff, 0xff, 0xff}
	draw.Draw(i, i.Bounds(), &image.Uniform{c}, image.ZP, draw.Src)
	gc := draw2d.NewGraphicContext(i)
	x := float64(PIECE_WIDTH)
	y := float64(IMG_HEIGHT) - 20.0
	for j := 0; j < len(r.TrackData.Elements); j++ {
		gc.MoveTo(x, y)
		elem := r.TrackData.Elements[j]
		seg := elem.Segment
		if elem.ChainLift {
			gc.SetStrokeColor(BLUE)
		} else {
			gc.SetStrokeColor(RED)
		}
		y -= 8.0 * float64(seg.ElevationDelta)
		gc.LineTo(float64(x+PIECE_WIDTH), y)
		gc.Stroke()
		x += PIECE_WIDTH
	}
	return i
}
開發者ID:kevinburke,項目名稱:rct-rides,代碼行數:25,代碼來源:2d.go

示例14: initGc

func initGc(w, h int) (image.Image, draw2d.GraphicContext) {
	d := image.NewRGBA(image.Rect(0, 0, w, h))
	gc := draw2d.NewGraphicContext(d)

	gc.SetStrokeColor(image.Black)
	gc.SetFillColor(image.White)
	return d, gc
}
開發者ID:Tony-Klink,項目名稱:disk_planing_FCFS,代碼行數:8,代碼來源:FCFS.go

示例15: main

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)
}
開發者ID:xushiwei,項目名稱:draw2d,代碼行數:8,代碼來源:gettingStarted.go


注:本文中的code/google/com/p/draw2d/draw2d.NewGraphicContext函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。