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
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+8k Golang : Sort words with first uppercase letter
+6.4k Golang : Break string into a slice of characters example
+17.5k Golang : Find smallest number in array
+9.2k Golang : How to check if a string with spaces in between is numeric?
+6.3k Golang : Test input string for unicode example
+14k Golang : Reverse IP address for reverse DNS lookup example
+9.3k Golang : Generate EAN barcode
+11.6k Golang : Fuzzy string search or approximate string matching example
+6.2k Golang & Javascript : How to save cropped image to file on server
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem