Golang image.Alpha.PixOffset function example
package image
func (p *Alpha) 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.Alpha.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.NewAlpha(bounds)
poffset := canvas.PixOffset(100, 100)
fmt.Println(poffset)
poffset = canvas.PixOffset(10, 10)
fmt.Println(poffset)
}
Sample output (depending on your image file) :
60100
6010
Reference :
Advertisement
Something interesting
Tutorials
+9.6k Golang : Read file with ioutil
+17.9k Golang : Qt image viewer example
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+13.5k Golang : Count number of runes in string
+5.4k Javascript : How to loop over and parse JSON data?
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+8.4k Golang : Ackermann function example
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+80.6k Golang : How to return HTTP status code?
+14.2k Golang : syscall.Socket example
+9.5k Mac OSX : Get a process/daemon status information
+5.7k Get website traffic ranking with Similar Web or Alexa