I am just learning Go and wrote the following struct (Image
) to implement the image.Image
interface.
package main
import (
"image"
"image/color"
"code.google.com/p/go-tour/pic"
)
type Image struct{}
func (img Image) ColorModel() color.Model {
return color.RGBAModel
}
func (img Image) Bounds() image.Rectangle {
return image.Rect(0, 0, 100, 100)
}
func (img Image) At(x, y int) color.Color {
return color.RGBA{100, 100, 255, 255}
}
func main() {
m := Image{}
pic.ShowImage(m)
}
If I just import image/color
and not import image
, image.Rect
is undefined. Why? Shouldn't image/color
already cover the methods and properties of image
?
Also, if I change the function receivers from (img Image)
to (img *Image)
, an error arises:
Image does not implement image.Image (At method requires pointer receiver)
Why is that? Doesn't (img *Image)
indicate a pointer receiver?