Golang image.NRGBA.PixOffset function example
package image
func (p *NRGBA) 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.NRGBA.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.NewNRGBA(bounds) // or NewNRGBA64
poffset := canvas.PixOffset(100, 100)
fmt.Println(poffset)
poffset = canvas.PixOffset(10, 10)
fmt.Println(poffset)
}
Sample output (depending on input image )
240400
24040
Reference :
Advertisement
Something interesting
Tutorials
+21.8k Golang : Convert string slice to struct and access with reflect example
+10.8k PHP : Convert(cast) bigInt to string
+10.8k Golang : Natural string sorting example
+11.9k Golang : Convert(cast) bigint to string
+7.5k Golang : Get YouTube playlist
+5.7k Golang : Error handling methods
+25.9k Golang : How to read integer value from standard input ?
+32.7k Golang : Regular Expression for alphanumeric and underscore
+11.6k Swift : Convert (cast) Float to String
+40.5k Golang : Convert to io.ReadSeeker type
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+30.5k Golang : Generate random string