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
+22.9k Golang : Test file read write permission example
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+6.9k Golang : Decode XML data from RSS feed
+5.9k Golang : Detect variable or constant type
+9.8k Golang : Get current, epoch time and display by year, month and day
+6k Golang : Experimenting with the Rejang script
+43.3k Golang : Convert []byte to image
+14k Golang : Google Drive API upload and rename example
+9.6k Javascript : Read/parse JSON data from HTTP response
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+6.7k Golang : Reverse by word