本文整理汇总了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()
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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
}
示例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)
}
}
示例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()
}
}
}
示例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
}
示例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)
}
示例12: GetTheImageGraphicContext
// Gets the singleton ImageGraphicContext.
func GetTheImageGraphicContext() *draw2d.ImageGraphicContext {
if graphicContextInstance == nil {
graphicContextInstance = draw2d.NewGraphicContext(GetTheImage().canvas)
}
return graphicContextInstance
}
示例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
}
示例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
}
示例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)
}