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
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+13.9k Golang : Get current time
+14.9k Golang : Basic authentication with .htpasswd file
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+6.1k Golang : Grab news article text and use NLP to get each paragraph's sentences
+9.8k Golang : Format strings to SEO friendly URL example
+6.4k PHP : Proper way to get UTF-8 character or string length
+6.3k Golang : Detect face in uploaded photo like GPlus
+11.1k Golang : Web routing/multiplex example
+6.5k Grep : How to grep for strings inside binary data
+5.4k How to check with curl if my website or the asset is gzipped ?
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?