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 :
Advertisement
Something interesting
Tutorials
+11k Golang : Generate random elements without repetition or duplicate
+13.4k Golang : Generate Code128 barcode
+8.2k Golang : Emulate NumPy way of creating matrix example
+9.7k Golang : Find correlation coefficient example
+21.8k Golang : Convert string slice to struct and access with reflect example
+7k Web : How to see your website from different countries?
+7.9k Golang Hello World Example
+4.9k Python : Find out the variable type and determine the type with simple test
+9.4k Facebook : Getting the friends list with PHP return JSON format
+21.3k Golang : Create and resolve(read) symbolic links
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+14k Golang : concatenate(combine) strings