本文整理汇总了Golang中github.com/BurntSushi/xgbutil/xgraphics.Image.SubImage方法的典型用法代码示例。如果您正苦于以下问题:Golang Image.SubImage方法的具体用法?Golang Image.SubImage怎么用?Golang Image.SubImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/BurntSushi/xgbutil/xgraphics.Image
的用法示例。
在下文中一共展示了Image.SubImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawPencil
// drawPencil takes an (x, y) position (from a MotionNotify event) and draws
// a rectangle of size pencilTip on to canvas.
func drawPencil(canvas *xgraphics.Image, win *xwindow.Window, x, y int) {
// Create a subimage at (x, y) with pencilTip width and height from canvas.
// Creating subimages is very cheap---no pixels are copied.
// Moreover, when subimages are drawn to the screen, only the pixels in
// the sub-image are sent to X.
tipRect := midRect(x, y, pencilTip, pencilTip, width, height)
// If the rectangle contains no pixels, don't draw anything.
if tipRect.Empty() {
return
}
// Output a little message.
log.Printf("Drawing pencil point at (%d, %d)", x, y)
// Create the subimage of the canvas to draw to.
tip := canvas.SubImage(tipRect)
fmt.Println(tip.Rect)
// Now color each pixel in tip with the pencil color.
tip.For(func(x, y int) xgraphics.BGRA {
return xgraphics.BlendBGRA(tip.At(x, y).(xgraphics.BGRA), pencil)
})
// Now draw the changes to the pixmap.
tip.XDraw()
// And paint them to the window.
tip.XPaint(win.Id)
}
示例2: drawGopher
// drawGopher draws the gopher image to the canvas.
func drawGopher(canvas *xgraphics.Image, gopher image.Image,
win *xwindow.Window, x, y int) {
// Find the rectangle of the canvas where we're going to draw the gopher.
gopherRect := midRect(x, y, gopherWidth, gopherHeight, width, height)
// If the rectangle contains no pixels, don't draw anything.
if gopherRect.Empty() {
return
}
// Output a little message.
log.Printf("Drawing gopher at (%d, %d)", x, y)
// Get a subimage of the gopher that's in sync with gopherRect.
gopherPt := image.Pt(gopher.Bounds().Min.X, gopher.Bounds().Min.Y)
if gopherRect.Min.X == 0 {
gopherPt.X = gopherWidth - gopherRect.Dx()
}
if gopherRect.Min.Y == 0 {
gopherPt.Y = gopherHeight - gopherRect.Dy()
}
// Create the canvas subimage.
subCanvas := canvas.SubImage(gopherRect)
// Blend the gopher image into the sub-canvas.
// This does alpha blending.
xgraphics.Blend(subCanvas, gopher, gopherPt)
// Now draw the changes to the pixmap.
subCanvas.XDraw()
// And paint them to the window.
subCanvas.XPaint(win.Id)
}