mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
doc: added The Go image package article
Orignally published on The Go Programming Language, September 21, 2011. http://blog.golang.org/2011/09/go-image-package.html Update #2547 R=adg, nigeltao CC=golang-dev https://golang.org/cl/5933049
This commit is contained in:
parent
81dbec12c8
commit
18f1a71dc2
16 changed files with 429 additions and 3 deletions
15
doc/progs/image_package1.go
Normal file
15
doc/progs/image_package1.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
p := image.Point{2, 1}
|
||||
fmt.Println("X is", p.X, "Y is", p.Y)
|
||||
}
|
||||
16
doc/progs/image_package2.go
Normal file
16
doc/progs/image_package2.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := image.Rect(2, 1, 5, 5)
|
||||
// Dx and Dy return a rectangle's width and height.
|
||||
fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0).In(r)) // prints 3 4 false
|
||||
}
|
||||
15
doc/progs/image_package3.go
Normal file
15
doc/progs/image_package3.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := image.Rect(2, 1, 5, 5).Add(image.Pt(-4, -2))
|
||||
fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0).In(r)) // prints 3 4 true
|
||||
}
|
||||
16
doc/progs/image_package4.go
Normal file
16
doc/progs/image_package4.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := image.Rect(0, 0, 4, 3).Intersect(image.Rect(2, 2, 5, 5))
|
||||
// Size returns a rectangle's width and height, as a Point.
|
||||
fmt.Printf("%#v\n", r.Size()) // prints image.Point{X:2, Y:1}
|
||||
}
|
||||
17
doc/progs/image_package5.go
Normal file
17
doc/progs/image_package5.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m := image.NewRGBA(image.Rect(0, 0, 640, 480))
|
||||
m.Set(5, 5, color.RGBA{255, 0, 0, 255})
|
||||
fmt.Println(m.At(5, 5))
|
||||
}
|
||||
17
doc/progs/image_package6.go
Normal file
17
doc/progs/image_package6.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m0 := image.NewRGBA(image.Rect(0, 0, 8, 5))
|
||||
m1 := m0.SubImage(image.Rect(1, 2, 5, 5)).(*image.RGBA)
|
||||
fmt.Println(m0.Bounds().Dx(), m1.Bounds().Dx()) // prints 8, 4
|
||||
fmt.Println(m0.Stride == m1.Stride) // prints true
|
||||
}
|
||||
|
|
@ -59,7 +59,16 @@ json="
|
|||
json5
|
||||
"
|
||||
|
||||
all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json slices go1)
|
||||
image_package="
|
||||
image_package1
|
||||
image_package2
|
||||
image_package3
|
||||
image_package4
|
||||
image_package5
|
||||
image_package6
|
||||
"
|
||||
|
||||
all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json $image_package slices go1)
|
||||
|
||||
for i in $all; do
|
||||
go build $i.go
|
||||
|
|
@ -87,9 +96,17 @@ testit eff_sequence '^\[-1 2 6 16 44\]$'
|
|||
testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$'
|
||||
|
||||
testit interface2 "^type: float64$"
|
||||
|
||||
testit json1 "^$"
|
||||
testit json2 "the reciprocal of i is"
|
||||
testit json3 "Age is int 6"
|
||||
testit json4 "^$"
|
||||
|
||||
testit image_package1 "^X is 2 Y is 1$"
|
||||
testit image_package2 "^3 4 false$"
|
||||
testit image_package3 "^3 4 true$"
|
||||
testit image_package4 "^image.Point{X:2, Y:1}$"
|
||||
testit image_package5 "^{255 0 0 255}$"
|
||||
testit image_package6 "^8 4 true$"
|
||||
|
||||
rm -f $all "$TMPFILE"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue