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
+11.1k Golang : Roll the dice example
+6.2k Golang & Javascript : How to save cropped image to file on server
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+14.4k Golang : How to pass map to html template and access the map's elements
+9.5k Mac OSX : Get a process/daemon status information
+9.4k Golang : Apply Histogram Equalization to color images
+16.8k Golang : read gzipped http response
+9.4k Golang : Generate EAN barcode
+19.2k Golang : Populate dropdown with html/template example
+36.5k Golang : Validate IP address
+40.1k Golang : UDP client server read write example
+7.8k Golang : Reverse a string with unicode