Golang image.Alpha.At function examples

package image

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

Golang image.Alpha.At function usage examples

Example 1:

 package main

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

 func init() {
 // damn important or else At(), Bounds() functions will
 // caused memory pointer error!!
 image.RegisterFormat("jpeg", "jpeg", jpeg.Decode, jpeg.DecodeConfig)
 }

 func main() {
 imgfile, err := os.Open("./img.jpg")

 if err != nil {
 fmt.Println("img.jpg file not found!")
 os.Exit(1)
 }

 defer imgfile.Close()

 img, _, err := image.Decode(imgfile)

 fmt.Println(img.At(10, 10)) // <-- here

 }

Output :

{255 128 128}

Example 2:

 img := image.NewAlpha(image.Rect(-1, -2, 3, 4))
 c := color.NRGBAModel.Convert(img.At(x, y)).(color.NRGBA)

Reference :

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

Advertisement