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
+17k Golang : Get number of CPU cores
+21.2k Golang : How to force compile or remove object files first before rebuild?
+18.4k Golang : How to get hour, minute, second from time?
+41.2k Golang : How to count duplicate items in slice/array?
+10.1k Golang : Identifying Golang HTTP client request
+19.4k Golang : How to count the number of repeated characters in a string?
+7k Golang : Levenshtein distance example
+26.7k Golang : How to check if a connection to database is still alive ?
+37.5k Golang : Converting a negative number to positive number
+34.1k Golang : Create x509 certificate, private and public keys
+4.8k Facebook : How to place save to Facebook button on your website
+14.3k Golang : Get uploaded file name or access uploaded files