Golang image.NewNRGBA function example
package image
func NewNRGBA(r Rectangle) *NRGBA
NewNRGBA returns a new NRGBA with the given bounds.
Golang image.NewNRGBA 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)
fmt.Println(img.At(10, 10))
bounds := img.Bounds()
fmt.Println(bounds)
canvas := image.NewNRGBA(bounds) // <-- here
stride := canvas.Stride
fmt.Println("Stride : ", stride)
}
Sample output :
{255 255 255 255}
(0,0)-(600,849)
Stride : 2400
Reference :
Advertisement
Something interesting
Tutorials
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+19.1k Mac OSX : Homebrew and Golang
+5.8k Golang : Find change in a combination of coins example
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+13.4k Golang : Generate Code128 barcode
+5.5k Golang : Display advertisement images or strings on random order
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+11.7k Golang : Secure file deletion with wipe example
+9.6k Golang : Validate IPv6 example
+6.3k Javascript : Generate random key with specific length
+21.1k Golang : For loop continue,break and range
+11.8k Golang : convert(cast) float to string