Trouble getting a SubImage of an Image in Go -


i'm doing image processing in go, , i'm trying subimage of image.

import (   "image/jpeg"   "os" ) func main(){   image_file, err := os.open("somefile.jpeg")   my_image, err := jpeg.decode(image_file)   my_sub_image := my_image.subimage(rect(j, i, j+x_width, i+y_width)).(*image.rgba) } 

when try compile that, .\img.go:8: picture.subimage undefined (type image.image has no field or method subimage).

any thoughts?

here alternative approach - use type assertion assert my_image has subimage method. work image type has subimage method (all of them except uniform @ quick scan). return image interface of unspecified type.

package main  import (     "fmt"     "image"     "image/jpeg"     "log"     "os" )  func main() {     image_file, err := os.open("somefile.jpeg")     if err != nil {         log.fatal(err)     }     my_image, err := jpeg.decode(image_file)     if err != nil {         log.fatal(err)     }      my_sub_image := my_image.(interface {         subimage(r image.rectangle) image.image     }).subimage(image.rect(0, 0, 10, 10))      fmt.printf("bounds %v\n", my_sub_image.bounds())  } 

if wanted lot create new type subimage interface , use that.

type subimager interface {     subimage(r image.rectangle) image.image }  my_sub_image := my_image.(subimager).subimage(image.rect(0, 0, 10, 10)) 

the usual caveats type assertions apply - use ,ok form if don't want panic.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -