Golang image.NRGBA and NRGBA64.At, ColorModel and Bounds functions example

package image

Golang image.NRGBA and NRGBA64.At, ColorModel and Bounds functions 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()

 canvas := image.NewNRGBA(bounds)

 fmt.Println(canvas.At(100,100))
 fmt.Println(canvas.Bounds())
 fmt.Println(canvas.ColorModel())
 }

References :

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

http://golang.org/pkg/image/#NRGBA.Bounds

http://golang.org/pkg/image/#NRGBA.ColorModel

Advertisement