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.5k Golang : How to check if input string is a word?
+17.5k Golang : Find smallest number in array
+18.5k Golang : Aligning strings to right, left and center with fill example
+7.5k Golang : Process json data with Jason package
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+15.3k Golang : How to get Unix file descriptor for console and file
+16.9k Golang : How to generate QR codes?
+14.2k Golang : Fix image: unknown format error
+36.3k Golang : Convert(cast) int64 to string
+36k Golang : Get file last modified date and time
+6.9k Mac OSX : Find large files by size
+9.5k Golang : Extract or copy items from map based on value