Golang image.Alpha16.PixOffset function example
package image
func (p *Alpha16) 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.Alpha16.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.NewAlpha16(bounds) // Alpha16
poffset := canvas.PixOffset(100, 100)
fmt.Println(poffset)
poffset = canvas.PixOffset(10, 10)
fmt.Println(poffset)
}
Reference :
Advertisement
Something interesting
Tutorials
+34.1k Golang : Create x509 certificate, private and public keys
+9k Golang : How to use Gorilla webtoolkit context package properly
+13k Golang : Calculate elapsed years or months since a date
+14.6k Golang : Execute function at intervals or after some delay
+11.8k Golang : Verify Linux user password again before executing a program example
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+8.4k Golang : Ackermann function example
+11.3k Golang : How to use if, eq and print properly in html template
+5.8k Golang : Find change in a combination of coins example
+5.7k Golang : Error handling methods