Golang image.Gray.PixOffset function example
package image
func (p *Gray) PixOffset(x, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
Golang image.Gray.PixOffset function usage example
package main
import (
"fmt"
"image"
"image/png"
"os"
)
func init() {
// without this register .. At(), Bounds() functions will
// caused memory pointer error!!
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
}
func main() {
imgfile, err := os.Open("./img.png")
if err != nil {
fmt.Println("img.png file not found!")
os.Exit(1)
}
defer imgfile.Close()
img, _, err := image.Decode(imgfile)
bounds := img.Bounds()
canvas := image.NewGray(bounds) // gray
poffset := canvas.PixOffset(100, 100)
fmt.Println(poffset)
poffset = canvas.PixOffset(10, 10)
fmt.Println(poffset)
}
Reference :
Advertisement
Something interesting
Tutorials
+6.3k Golang : Test input string for unicode example
+6.7k Golang : Skip or discard items of non-interest when iterating example
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+5.8k Golang : Markov chains to predict probability of next state example
+14.9k Golang : How to check for empty array string or string?
+11k Golang : Create S3 bucket with official aws-sdk-go package
+11.3k Golang : How to use if, eq and print properly in html template
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+3.6k Java : Get FX sentiment from website example
+12.8k Golang : http.Get example
+20.2k Golang : Count number of digits from given integer value
+18.8k Golang : Implement getters and setters