[Go语言]我的第九个Go语言程序
2016-08-01 21:20
162 查看
Exercise: Images
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Imageinstead
of a slice of data.
Define your own
Imagetype, implement the
necessary methods, and call
pic.ShowImage.
Boundsshould return a
image.Rectangle,
like
image.Rect(0, 0, w, h).
ColorModelshould return
color.RGBAModel.
Atshould return a color; the value
vin
the last picture generator corresponds to
color.RGBA{v, v, 255, 255}in this one.
package main import ( "golang.org/x/tour/pic" "image" "image/color" ) 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{uint8(x ^ y), uint8(x ^ y), 255, 255} } func main() { m := Image{} pic.ShowImage(m) }
相关文章推荐
- Go语言日趋成熟 运行速度接近C语言实现程序
- go语言 -并行程序 wordcount
- 创建第一个Go语言程序Hello,Go!
- go语言实现的目录共享程序
- 关于GDB调试go语言程序中出现 os.Args无法打印的问题
- Go语言学习札记——第三章 Go基本的程序设计结构(1)
- 在Go语言程序中使用gojson来解析JSON格式文件
- Go语言程序的状态监控 via 达达
- go语言编写,简单聊天室程序 1
- 使用GO语言开发 Redis数据监控程序
- Goclipse中运行Go语言程序的配置
- go语言编写Web程序
- 我的第一个比较实用的GO语言程序
- Go语言程序的状态监控
- Go 语言中实现优雅的停止程序
- 在go语言中统计程序执行时间
- Eclipse里编写Go语言程序
- Sublim Text 开发Go语言程序
- Windows下使用go语言写程序安装配置实例
- Go语言监控文件变化小程序.