Golang image.NRGBA and NRGBA64.Set and SetNRGBA(64) functions example
package image
Golang image.NRGBA and NRGBA64.Set and SetNRGBA(64) functions usage example
package main
import (
"fmt"
"image"
"image/color" // for color.NRGBA or color.NRGBA64
"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.NewNRGBA(bounds) // or NewNRGBA64
canvas.Set(100, 100, image.Transparent)
// http://golang.org/pkg/image/color/#NRGBA
// NRGBA represents a non-alpha-premultiplied 32-bit color.
x := 512
y := 512
r := uint8(255) // type NRGBA or uint16 for type NRGBA64
g := uint8(255) // type NRGBA or uint16 for type NRGBA64
b := uint8(255) // type NRGBA or uint16 for type NRGBA64
a := uint8(255) // type NRGBA or uint16 for type NRGBA64
canvas.SetNRGBA(x, y, color.NRGBA{r,g,b,a})
}
References :
http://golang.org/pkg/image/#NRGBA.Set
http://golang.org/pkg/image/#NRGBA.SetNRGBA
Advertisement
Something interesting
Tutorials
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+29.5k Golang : Login(Authenticate) with Facebook example
+5.7k List of Golang XML tutorials
+9.4k Golang : Qt Yes No and Quit message box example
+12.6k Golang : Transform comma separated string to slice example
+13.8k Golang : Gin framework accept query string by post request example
+23.2k Golang : Print out struct values in string format
+9.5k Golang : Accessing content anonymously with Tor
+9.9k Golang : Turn string or text file into slice example
+9.6k Golang : Sort and reverse sort a slice of floats
+11.4k Golang : Concatenate (combine) buffer data example