Golang image.Gray.Bounds function example
package image
func (p *Gray) Bounds() Rectangle
Golang image.Gray.Bounds 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)
bounds := img.Bounds()
grayrect := image.NewGray(bounds)
rect := grayrect.Bounds() // <-- here
fmt.Println("Min X : Y = ", rect.Min.X, rect.Min.Y)
fmt.Println("Max X : Y = ", rect.Max.X, rect.Max.Y)
}
Sample output(depending on input image ) :
Min X : Y = 0 0
Max X : Y = 600 849
Reference :
Advertisement
Something interesting
Tutorials
+30.4k Golang : How to redirect to new page with net/http?
+25.2k Golang : Storing cookies in http.CookieJar example
+6.5k Golang : Convert an executable file into []byte example
+23.2k Golang : Print out struct values in string format
+7.5k Gogland : Single File versus Go Application Run Configurations
+6.4k Golang : Break string into a slice of characters example
+19.1k Golang : Display list of time zones with GMT
+16k Golang : Generate universally unique identifier(UUID) example
+16.6k Golang : Delete files by extension
+32.7k Golang : Regular Expression for alphanumeric and underscore
+15.9k Golang : Get current time from the Internet time server(ntp) example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided