本文整理匯總了Golang中image.Point類的典型用法代碼示例。如果您正苦於以下問題:Golang Point類的具體用法?Golang Point怎麽用?Golang Point使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Point類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RenderMultiline
func (c *Context) RenderMultiline(txt []string, size float64, bg, fg color.Color) (*image.RGBA, error) {
w, h := 0, 0
imgs := []*image.RGBA{}
for _, l := range txt {
i, err := c.Render(l, size, fg)
if err != nil {
return nil, err
}
if i.Bounds().Dx() > w {
w = i.Bounds().Dx()
}
h += i.Bounds().Dy()
imgs = append(imgs, i)
}
dst := image.NewRGBA(image.Rect(0, 0, w, h))
draw.Draw(dst, dst.Bounds(), image.NewUniform(bg), image.ZP, draw.Src)
y := 0
for _, src := range imgs {
sr := src.Bounds()
dp := image.Point{0, y}
r := image.Rectangle{dp, dp.Add(sr.Size())}
draw.Draw(dst, r, src, sr.Min, draw.Src)
y += sr.Dy()
}
return dst, nil
}
示例2: Draw
// Draw renders the given cpu cores on img.
func (app *App) Draw(img draw.Image, cpus []CPU) {
rect := img.Bounds()
bg := app.Background
if bg == nil {
bg = image.Black
}
draw.Draw(img, rect, bg, bg.Bounds().Min, draw.Over)
if len(cpus) == 0 {
return
}
cpuDx := rect.Dx() / len(cpus)
ptIncr := image.Point{X: cpuDx}
ptDelta := image.Point{}
rectDx := image.Rectangle{
Min: rect.Min,
Max: rect.Max,
}
rectDx.Max.X = rect.Min.X + cpuDx
for _, cpu := range cpus {
irect := image.Rectangle{
Min: rectDx.Min.Add(ptDelta),
Max: rectDx.Max.Add(ptDelta),
}
subimg := SubImage(img, irect)
app.renderCPU(subimg, cpu)
ptDelta = ptDelta.Add(ptIncr)
}
}
示例3: parseImgBoundary
func parseImgBoundary(img image.Image) {
minX, maxX := img.Bounds().Min.X, img.Bounds().Max.X
minY, maxY := img.Bounds().Min.Y, img.Bounds().Max.Y
for i := minX; i < maxX; i++ {
for j := minY; j < maxY; j++ {
_, _, _, a := img.At(i, j).RGBA()
if a != 0 {
if boundary.Empty() && boundary.Min.X == -1 {
boundary = image.Rect(i, j, i, j)
} else {
_p := image.Point{i, j}
if !_p.In(boundary) {
boundary = boundary.Union(image.Rect(i, j, i, j))
}
}
}
}
}
// Should Make the midline of boundary and the img
l := boundary.Min.X
r := imageW - boundary.Max.X
if l > r {
boundary.Min.X = r
} else if l < r {
boundary.Max.X = imageW - l
}
}
示例4: originTrans
// originTrans translates the origin with respect to the current image and the
// current canvas size. This makes sure we never incorrect position the image.
// (i.e., panning never goes too far, and whenever the canvas is bigger than
// the image, the origin is *always* (0, 0).
func originTrans(pt image.Point, win *window, img *vimage) image.Point {
// If there's no valid image, then always return (0, 0).
if img == nil {
return image.Point{0, 0}
}
// Quick aliases.
ww, wh := win.Geom.Width(), win.Geom.Height()
dw := img.Bounds().Dx() - ww
dh := img.Bounds().Dy() - wh
// Set the allowable range of the origin point of the image.
// i.e., never less than (0, 0) and never greater than the width/height
// of the image that isn't viewable at any given point (which is determined
// by the canvas size).
pt.X = min(img.Bounds().Min.X+dw, max(pt.X, 0))
pt.Y = min(img.Bounds().Min.Y+dh, max(pt.Y, 0))
// Validate origin point. If the width/height of an image is smaller than
// the canvas width/height, then the image origin cannot change in x/y
// direction.
if img.Bounds().Dx() < ww {
pt.X = 0
}
if img.Bounds().Dy() < wh {
pt.Y = 0
}
return pt
}
示例5: _draw
func (f *Frame) _draw(pt image.Point) image.Point {
for nb := 0; nb < f.nbox; nb++ {
b := f.box[nb]
f.cklinewrap0(&pt, b)
if pt.Y == f.Rect.Max.Y {
f.nchars -= f.strlen(nb)
f.delbox(nb, f.nbox-1)
break
}
if b.Nrune > 0 {
n, fits := f.canfit(pt, b)
if !fits {
break
}
if n != b.Nrune {
f.splitbox(uint64(nb), uint64(n))
b = f.box[nb]
}
pt.X += b.Wid
} else {
if b.Bc == '\n' {
pt.X = f.Rect.Min.X
pt.Y += f.Font.Height
} else {
pt.X += f.newwid(pt, b)
}
}
}
return pt
}
示例6: resizeIfNec
// Clones the image if resize is not necessary.
func resizeIfNec(size image.Point, im image.Image, interp resize.InterpolationFunction) image.Image {
if size.Eq(im.Bounds().Size()) {
return clone(im)
}
log.Printf("resize %v to %v", im.Bounds().Size(), size)
return resize.Resize(uint(size.X), uint(size.Y), im, interp)
}
示例7: At
func (d *dimensionChanger) At(x, y int) color.Color {
p := image.Point{x, y}
if !p.In(d.bounds) {
return nil
}
return d.Image.At(x*d.pixel.Dx()+d.Image.Bounds().Canon().Min.X, y*d.pixel.Dy()+d.Image.Bounds().Canon().Min.Y)
}
示例8: main
func main() {
bounds := image.Rect(0, 0, 100, 100)
im := image.NewGray(bounds)
gBlack := color.Gray{0}
gWhite := color.Gray{255}
draw.Draw(im, bounds, image.NewUniform(gWhite), image.ZP, draw.Src)
pos := image.Point{50, 50}
dir := up
for pos.In(bounds) {
switch im.At(pos.X, pos.Y).(color.Gray).Y {
case gBlack.Y:
im.SetGray(pos.X, pos.Y, gWhite)
dir--
case gWhite.Y:
im.SetGray(pos.X, pos.Y, gBlack)
dir++
}
if dir&1 == 1 {
pos.X += 1 - dir&2
} else {
pos.Y -= 1 - dir&2
}
}
f, err := os.Create("ant.png")
if err != nil {
fmt.Println(err)
return
}
if err = png.Encode(f, im); err != nil {
fmt.Println(err)
}
if err = f.Close(); err != nil {
fmt.Println(err)
}
}
示例9: sourceRectTouchOriginalFromInside
func (self *Image) sourceRectTouchOriginalFromInside(width, height int, horAlign HorAlignment, verAlign VerAlignment) (r image.Rectangle) {
var offset image.Point
aspectRatio := float64(width) / float64(height)
if aspectRatio > self.AspectRatio() {
// Wider than original
// so touchOriginalFromInside means
// that the source rect is as wide as the original
r.Max.X = self.Width()
r.Max.Y = int(float64(self.Width()) / aspectRatio)
switch verAlign {
case VerCenter:
offset.Y = (self.Height() - r.Max.Y) / 2
case Bottom:
offset.Y = self.Height() - r.Max.Y
}
} else {
// Heigher than original,
// so touchOriginalFromInside means
// that the source rect is as high as the original
r.Max.X = int(float64(self.Height()) * aspectRatio)
r.Max.Y = self.Height()
switch horAlign {
case HorCenter:
offset.X = (self.Width() - r.Max.X) / 2
case Right:
offset.X = self.Width() - r.Max.X
}
}
return r.Add(offset)
}
示例10: Set
func (si *subimage) Set(x, y int, c color.Color) {
p := image.Point{x + si.bounds.Min.X, y + si.bounds.Min.Y}
if !p.In(si.Bounds()) {
return
}
si.Image.Set(p.X, p.Y, c)
}
示例11: addPixel
func (b *bucket) addPixel(pixel image.Point) {
b.group.wire.pixels = append(b.group.wire.pixels, pixel)
b.group.wire.bounds = b.group.wire.bounds.Union(
image.Rectangle{
pixel,
pixel.Add(image.Point{1, 1})})
}
示例12: At
func (si *subimage) At(x, y int) color.Color {
p := image.Point{x + si.bounds.Min.X, y + si.bounds.Min.Y}
if !p.In(si.Bounds()) {
return color.Black
}
return si.Image.At(p.X, p.Y)
}
示例13: Paste
// Paste pastes the img image to the background image at the specified position and returns the combined image.
func Paste(background, img image.Image, pos image.Point) *image.NRGBA {
src := toNRGBA(img)
dst := Clone(background) // cloned image bounds start at (0, 0)
startPt := pos.Sub(background.Bounds().Min) // so we should translate start point
endPt := startPt.Add(src.Bounds().Size())
pasteBounds := image.Rectangle{startPt, endPt}
if dst.Bounds().Overlaps(pasteBounds) {
intersectBounds := dst.Bounds().Intersect(pasteBounds)
rowSize := intersectBounds.Dx() * 4
numRows := intersectBounds.Dy()
srcStartX := intersectBounds.Min.X - pasteBounds.Min.X
srcStartY := intersectBounds.Min.Y - pasteBounds.Min.Y
i0 := dst.PixOffset(intersectBounds.Min.X, intersectBounds.Min.Y)
j0 := src.PixOffset(srcStartX, srcStartY)
di := dst.Stride
dj := src.Stride
for row := 0; row < numRows; row++ {
copy(dst.Pix[i0:i0+rowSize], src.Pix[j0:j0+rowSize])
i0 += di
j0 += dj
}
}
return dst
}
示例14: Set
func (i *imageSlice) Set(x, y int, c color.Color) {
p := image.Point{x, y}
if p.In(i.r) {
p = p.Add(i.p)
i.img.Set(p.X, p.Y, c)
}
}
示例15: canfit
func canfit(p *Piece) bool {
var dx = [...]int{0, -1, 1, -2, 2, -3, 3, 4, -4}
j := N + 1
if j >= 4 {
j = p.sz.X
if j < p.sz.Y {
j = p.sz.Y
}
j = 2*j - 1
}
for i := 0; i < j; i++ {
var z image.Point
z.X = pos.X + dx[i]*pcsz
z.Y = pos.Y
if !collide(z, p) {
z.Y = pos.Y + pcsz - 1
if !collide(z, p) {
undrawpiece()
pos.X = z.X
return true
}
}
}
return false
}