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
+14.5k Golang : Rename directory
+32.5k Golang : Copy directory - including sub-directories and files
+18k Golang : How to log each HTTP request to your web server?
+47.8k Golang : Convert int to byte array([]byte)
+22.6k Generate checksum for a file in Go
+20.8k Golang : Underscore or snake_case to camel case example
+8.2k Golang : Routes multiplexer routing example with regular expression control
+14.6k Golang : How to get URL port?
+6.3k Golang : How to get capacity of a slice or array?
+12.2k Golang : calculate elapsed run time