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
+9k Golang : Go as a script or running go with shebang/hashbang style
+5.1k Golang : Display packages names during compilation
+6.5k Golang : Combine slices of complex numbers and operation example
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+14.4k Golang : How to convert a number to words
+36k Golang : Get file last modified date and time
+5.8k Golang : Find change in a combination of coins example
+6.9k Nginx : Password protect a directory/folder
+6.9k Golang : Decode XML data from RSS feed
+5k Golang : Constant and variable names in native language
+15.8k Golang : Get digits from integer before and after given position example