go语言Exercise: Images
来源:互联网 发布:java工资一般多少 编辑:程序博客网 时间:2024/06/06 18:20
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation ofimage.Image
instead of a slice of data.
Define your own Image
type, implement the necessary methods, and call pic.ShowImage
.
Bounds
should return a image.Rectangle
, like image.Rect(0, 0, w, h)
.
ColorModel
should return color.RGBAModel
.
At
should return a color; the value v
in the last picture generator corresponds to color.RGBA{v, v, 255, 255}
in this one.
package main
import (
"image"
"image/color"
"tour/pic"
)
type Image struct{}
func (i *Image) ColorModel() color.Model {
return color.RGBAModel
}
func (i *Image) Bounds() image.Rectangle {
return image.Rect(0, 0, 256, 256)
}
func (i *Image) At(x, y int) color.Color {
v := (uint8)(x^y)
return color.RGBA{v, v, 255, 255}
}
func main() {
m := &Image{}
pic.ShowImage(m)
}
- go语言Exercise: Images
- go语言Exercise: Maps
- go语言Exercise: Slices
- go语言Exercise: Errors
- go语言Exercise: Fibonacci closure
- go语言Exercise: Rot13 Reader
- 【GoLang笔记】A Tour of Go - Exercise: Images
- Go 语言实现exercise--Loops and Functions
- go语言Advanced Exercise: Complex cube roots
- go语言Exercise: Equivalent Binary Trees
- Go Exercise: Equivalent Binary Trees
- A Tour of Go: Exercise: Rot13 Reader
- golang官方指导练习(go tour exercise)
- A Tour of Go---Exercise: Fibonacci closure
- 【Go】Go语言初学
- Go语言
- Go语言
- Go语言
- shell-003 通配符 与 转义字符
- scbarg.cpp(57): error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CSizingControlBar
- 从头到尾讲解EJB MDB(消息驱动bean)二——MDB实现技术
- Struts2开发环境配置
- 如何改变UITabBarController中tabBar和UINavigationController中navigationBarr的颜色
- go语言Exercise: Images
- SVM入门(二)线性分类器Part 1
- 探索NDIS HOOK新的实现方法(2)
- SVM入门(三)线性分类器Part 2
- 牛人主页(主页有很多论文代码)
- linux shell编程入门
- SVM入门(四)线性分类器的求解——问题的描述Part1
- 物理机迁移到虚拟机EXSI4.1 SERVER实验
- SVM入门(五)线性分类器的求解——问题的描述Part2