本文整理匯總了Golang中image.Rectangle.Sub方法的典型用法代碼示例。如果您正苦於以下問題:Golang Rectangle.Sub方法的具體用法?Golang Rectangle.Sub怎麽用?Golang Rectangle.Sub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類image.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Sub方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: upload
func (b *bufferImpl) upload(u screen.Uploader, xd xproto.Drawable, xg xproto.Gcontext, depth uint8,
dp image.Point, sr image.Rectangle, sender screen.Sender) {
b.preUpload(sender != nil)
// TODO: adjust if dp is outside dst bounds, or sr is outside src bounds.
dr := sr.Sub(sr.Min).Add(dp)
b.s.mu.Lock()
b.s.nPendingUploads++
b.s.mu.Unlock()
cookie := shm.PutImage(
b.s.xc, xd, xg,
uint16(b.size.X), uint16(b.size.Y), // TotalWidth, TotalHeight,
uint16(sr.Min.X), uint16(sr.Min.Y), // SrcX, SrcY,
uint16(dr.Dx()), uint16(dr.Dy()), // SrcWidth, SrcHeight,
int16(dr.Min.X), int16(dr.Min.Y), // DstX, DstY,
depth, xproto.ImageFormatZPixmap,
1, b.xs, 0, // 1 means send a completion event, 0 means a zero offset.
)
b.s.mu.Lock()
b.s.uploads[cookie.Sequence] = completion{
sender: sender,
event: screen.UploadedEvent{
Buffer: b,
Uploader: u,
},
}
b.s.nPendingUploads--
b.s.handleCompletions()
b.s.mu.Unlock()
}
示例2: OnHostPaint
func (h *HostWindow) OnHostPaint(ctxt NativeContext, dirty_rect image.Rectangle) {
var canvas = NewNativeCanvas(dirty_rect)
defer canvas.Release()
var canvas_rect = dirty_rect.Sub(dirty_rect.Min)
canvas.DrawCanvas(canvas_rect.Min.X, canvas_rect.Min.Y,
h.root_view.Canvas(), &dirty_rect)
canvas.BlitToContext(ctxt, dirty_rect.Min.X, dirty_rect.Min.Y, &canvas_rect)
}
示例3: ChartArea
// ChartArea returns the smallest rectangle containing all chart positions
// that can get drawn in the given screen rectangle, if chart position (0, 0)
// is at the center of the screen rectangle.
func ChartArea(screenArea image.Rectangle) image.Rectangle {
scrOrigin := CenterOrigin(screenArea)
minX, minY := math.MaxInt32, math.MaxInt32
maxX, maxY := math.MinInt32, math.MinInt32
for _, pt := range Corners(screenArea.Sub(scrOrigin)) {
chartPos := ScreenToChart(pt)
minX = int(math.Min(float64(chartPos.X), float64(minX)))
minY = int(math.Min(float64(chartPos.Y), float64(minY)))
maxX = int(math.Max(float64(chartPos.X), float64(maxX)))
maxY = int(math.Max(float64(chartPos.Y), float64(maxY)))
}
return image.Rect(minX, minY, maxX+1, maxY+1)
}
示例4: Draw
// Draw creates an image of the function in the domain.
func Draw(fnc ColorMap, size image.Rectangle, domain *ComplexRect) image.Image {
size = size.Canon()
// Clever vector hack to move the Min corner to 0,0
size = size.Sub(size.Min)
// For now, use RGBA as image type
img := image.NewRGBA(size)
// max x and y guaranteed to be size of rectangle
x := size.Dx()
y := size.Dy()
dx := domain.dx() / float64(x)
dy := domain.dy() / float64(y)
// Get the initial x vals
base_x := domain.left()
base_y := domain.bottom()
for i := 0; i <= x; i++ {
for j := 0; j <= y; j++ {
point := complex(base_x+float64(i)*dx, base_y+float64(j)*dy)
img.Set(i, j, fnc(point))
}
}
return img
}
示例5: Crop
// Crop cuts out a rectangular region with the specified bounds
// from the image and returns the cropped image.
func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
src := toNRGBA(img)
srcRect := rect.Sub(img.Bounds().Min)
sub := src.SubImage(srcRect)
return Clone(sub) // New image Bounds().Min point will be (0, 0)
}
示例6: CropTo
// CropTo returns a copy of this image that has been cropped
// to the given dimensions
func (self Image) CropTo(bounds image.Rectangle) Image {
dst := image.NewRGBA(bounds.Sub(bounds.Min))
r := image.Rectangle{dst.Rect.Min, dst.Rect.Min.Add(bounds.Size())}
draw.Draw(dst, r, self.Img, bounds.Min, draw.Src)
return Image{Img: dst, Format: self.Format}
}
示例7: Crop
func Crop(context *common.AppContext, img image.Image, rect image.Rectangle) *image.NRGBA {
src := ToNRGBA(img)
srcRect := rect.Sub(img.Bounds().Min)
sub := src.SubImage(srcRect)
return CloneImage(sub)
}