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
+11.5k Golang : Generate DSA private, public key and PEM files example
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+9.4k Golang : Find the length of big.Int variable example
+8.3k Golang : Emulate NumPy way of creating matrix example
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+6.1k Golang : Dealing with backquote
+16.3k Golang : convert string or integer to big.Int type
+11.9k Golang : Convert(cast) bigint to string
+16.4k Golang : Send email and SMTP configuration example
+19.2k Golang : Check whether a network interface is up on your machine
+11k How to test Facebook App on localhost ?