Golang image.NewGray function examples
package image
func NewGray(r Rectangle) *Gray
NewGray returns a new Gray with the given bounds.
Golang image.NewGray function usage examples
Example 1:
package main
import (
"fmt"
"image"
"image/png"
"os"
)
func init() {
// without this register .. At(), Bounds() functions will
// caused memory pointer error!!
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)
bounds := img.Bounds()
newgraycanvas := image.NewGray(bounds)
rect := image.Rect(0, 0, 100, 100)
subimg := newgraycanvas.SubImage(rect)
fmt.Println(subimg.Bounds())
fmt.Println(subimg.At(10, 10))
}
Example 2:
imgRect := image.Rect(0, 0, 200, 200)
img := image.NewGray(imgRect)
References :
Advertisement
Something interesting
Tutorials
+15k Golang : How do I get the local IP (non-loopback) address ?
+5.4k Golang *File points to a file or directory ?
+5.7k Golang : Error handling methods
+4.9k Javascript : How to get width and height of a div?
+19.7k Golang : Archive directory with tar and gzip
+11.1k Golang : Web routing/multiplex example
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+22.9k Golang : Gorilla mux routing example
+9k Golang : Capture text return from exec function example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+24k Golang : Call function from another package
+17.6k Convert JSON to CSV in Golang