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
+9.2k Golang : How to check if a string with spaces in between is numeric?
+14k Golang : concatenate(combine) strings
+6k Javascript : Get operating system and browser information
+17.9k Golang : Qt image viewer example
+6.8k Swift : substringWithRange() function example
+4.9k Nginx and PageSpeed build from source CentOS example
+17.9k Golang : Login and logout a user after password verification and redirect example
+11.1k Golang : Web routing/multiplex example
+14.5k Golang : How to determine if user agent is a mobile device example
+30.9k error: trying to remove "yum", which is protected
+10.7k Golang : Get currencies exchange rates example