本文整理匯總了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)
}