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
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+8.8k Golang : HTTP Routing with Goji example
+5.4k Golang *File points to a file or directory ?
+13k Swift : Convert (cast) Int to String ?
+12k Golang : Find and draw contours with OpenCV example
+7.9k Golang : Ways to recover memory during run time.
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+5.3k Golang : How to deal with configuration data?
+80.6k Golang : How to return HTTP status code?
+9.4k Golang : Qt Yes No and Quit message box example