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
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+4.8k PHP : Extract part of a string starting from the middle
+12.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+36.3k Golang : Convert(cast) int64 to string
+7.5k Gogland : Single File versus Go Application Run Configurations
+10.6k Golang : Simple File Server
+5.7k Golang : Frobnicate or tweaking a string example
+16.4k Golang : How to implement two-factor authentication?
+37.5k Upload multiple files with Go
+36.3k Golang : How to split or chunking a file to smaller pieces?