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
+8.6k Golang : Set or add headers for many or different handlers
+6.5k Golang : Convert an executable file into []byte example
+9.6k Golang : Quadratic example
+10.6k Golang : Flip coin example
+22.2k Golang : Convert seconds to minutes and remainder seconds
+9.7k Golang : interface - when and where to use examples
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+15.8k Golang : How to login and logout with JWT example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+6.1k Golang : Create new color from command line parameters
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)