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.1k Golang : Convert file content to Hex
+6.6k Golang : Generate human readable password
+7.9k Golang : How to get username from email address
+6.5k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+4.6k PHP : Convert CSV to JSON with YQL example
+8.5k Golang : interface - when and where to use examples
+7.7k Golang : Gorilla web tool kit schema example
+12.8k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+10.6k Golang : Convert(cast) float to int
+27.2k Golang : Detect (OS) Operating System
+5.2k Linux/Unix : Commands that you need to be careful about
+21.2k Golang : Set and Get HTTP request headers example