Golang image.Gray.At function example

package image

 func (p *Gray) At(x, y int) color.Color
  

Golang image.Gray.At function usage example

 package main

 import (
 "fmt"
 "image"
 "image/png"
 "os"
 )

 func init() {
 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()

 grayrect := image.NewGray(bounds) // <-- here

 // see http://golang.org/pkg/image/color/#Color
 color := grayrect.At(100, 100) // <--- HERE

 fmt.Println(color)
 fmt.Println(color.RGBA())
 }

Reference :

http://golang.org/pkg/image/#Gray.At

Advertisement