Golang image.Alpha16.Set and SetAlpha16 functions example

package image

 func (p *Alpha16) Set(x, y int, c color.Color)
  

Golang image.Alpha16.Set and SetAlpha functions usage example

 package main

 import (
 "fmt"
 "image"
 "image/color" // for color.Alpha{a}
 "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) // for Alpha16

 canvas.Set(100, 100, image.Transparent)

 // http://golang.org/pkg/image/color/#Alpha16
 // Alpha16 represents an 16-bit alpha color.

 x := 10
 y := 10
 a := uint16((23*x + 29*y) % 0x100)

 canvas.SetAlpha16(x, y, color.Alpha16{a})

 }

Reference :

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

Advertisement