Golang image.Alpha16.Bounds function example

package image

 func (p *Alpha16) Bounds() Rectangle
  

Golang image.Alpha16.Bounds 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()

 alpha16 := image.NewAlpha16(bounds)

 rect := alpha16.Bounds() // <-- here

 fmt.Println("Min X : Y = ", rect.Min.X, rect.Min.Y)

 fmt.Println("Max X : Y = ", rect.Max.X, rect.Max.Y)
 }

Sample output ( depending on image file ) :

Min X : Y = 0 0

Max X : Y = 600 849

Reference :

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

Advertisement