我正在练习:https://tour.golang.org/methods/25的图像,我遇到了问题。这是我的代码......
<div class="panel-body">
<div id="listingTable">
<ul id = "Mylinks" class="paging">
<li style="display: none;"><a href="http://site1.com" rel="nofollow">Description1</a></li>
<li style="display: none;"><a href="http://site2.com" rel="nofollow">Description2</a></li>
<li style="display: none;"><a href="http://site3.com" rel="nofollow">Description3</a></li>
<li style="display: none;"><a href="http://site4.com" rel="nofollow">Description4</a></li>
<li style="display: none;"><a href="http://site5.com" rel="nofollow">Description5</a></li>
<li style="display: none;"><a href="http://site6.com" rel="nofollow">Description6</a></li>
<li style="display: none;"><a href="http://site7.com" rel="nofollow">Description7</a></li>
<li style="display: none;"><a href="http://site100.com" rel="nofollow">Description100</a></li>
<!-- Number of links is unlimited. -->
</ul>
</div>
<ul class="pager">
<li><a href="javascript:prevPage()" id="btn_prev">previous</a></li>
<li><a href="javascript:nextPage()" id="btn_next">next</a></li>
</ul>
</div>
它给了我错误......
package main
import (
"golang.org/x/tour/pic"
"image"
)
type Image struct{
image *image.RGBA
}
func main() {
rect := image.Rect(0,0,255,255)
myImage := image.NewRGBA(rect)
m := Image{myImage}
pic.ShowImage(m)
}
但是tmp/sandbox089594299/main.go:16: cannot use m (type Image) as type image.Image in argument to pic.ShowImage:
Image does not implement image.Image (missing At method)
会返回image.NewRGBA
,而且确实有*NRGBA
方法。另外我假设,因为At()
方法是At()
接口所需的最后一个方法,所以它正在寻找另外两个必需的方法......那么image.Image
是什么?
image.NRGBA:https://golang.org/pkg/image/#NRGBA
image.Image interface:https://golang.org/pkg/image/#Image
答案 0 :(得分:1)
您的类型Image
未实施At
方法。如果您希望类型继承*image.RGBA
实现的方法,请使用匿名字段:
type Image struct{
*image.RGBA
}