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.6k Golang : Progress bar with ∎ character
+11.5k Golang : Change date format to yyyy-mm-dd
+13.6k Android Studio : Password input and reveal password example
+5.6k Golang : Detect words using using consecutive letters in a given string
+7k Golang : Gargish-English language translator
+10.9k Golang : How to transmit update file to client by HTTP request example
+17.7k Golang : [json: cannot unmarshal object into Go value of type]
+11.3k Golang : How to flush a channel before the end of program?
+32.4k Golang : Math pow(the power of x^y) example
+13.6k Golang : Query string with space symbol %20 in between
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+15.6k Golang : rune literal not terminated error