13. 이미지 ( Image )
: Package image 는 Image 인터페이스를 정의합니다.
package image
type Image interface {
ColorModel()
color.Model Bounds()
Rectangle At(x, y int)
color.Color
}
( https://golang.org/pkg/image/#Image )
또한, color.Color 와 color.Model 는 인터페이스이지만, 미리 정의된 구현체인 color.RGBA 와 color.RGBAModel 을 사용함으로써 그 인터페이스를 무시할 수 있다.
import (
"fmt"
"image"
)
func main() {
m := image.NewRGBA(image.Rect(0, 0, 100, 100))
fmt.Println(m.Bounds())
fmt.Println(m.At(0, 0).RGBA())
}
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct{
width int
height int
}
func (img Image) ColorModel() color.Model {
return color.RGBAModel
}
func (img Image) Bounds() image.Rectangle {
return image.Rect(0, 0, img.width, img.height)
}
func (img Image) At(x, y int) color.Color {
img_func := func(x, y int) uint8 {
return uint8(x^y)
}
v := img_func(x, y)
return color.RGBA{v, v, 255, 255}
}
func main() {
m := Image{256,256}
pic.ShowImage(m)
}