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
+5k Golang : micron to centimeter example
+9k Golang : Go as a script or running go with shebang/hashbang style
+5k Golang : Constant and variable names in native language
+5.6k Unix/Linux : How to find out the hard disk size?
+51.4k Golang : Check if item is in slice/array
+7.4k Golang : Convert source code to assembly language
+11.5k Golang : Handle API query by curl with Gorilla Queries example
+6.5k Grep : How to grep for strings inside binary data
+8.1k Golang : Append and add item in slice
+4.9k Python : Find out the variable type and determine the type with simple test
+13.9k Golang : How to check if a file is hidden?
+26.4k Golang : Convert(cast) string to uint8 type and back to string