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
+9k Golang : How to use Gorilla webtoolkit context package properly
+5.3k Javascript : Change page title to get viewer attention
+10.8k Android Studio : Checkbox for user to select options example
+18.5k Golang : Send email with attachment
+4.1k Javascript : Empty an array example
+10.8k Golang : Natural string sorting example
+23.5k Golang : Check if element exist in map
+11.1k Golang : Roll the dice example
+6.9k Golang : Calculate BMI and risk category
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+8.8k Yum Error: no such table: packages