Commit 18f1a71d authored by Francisco Souza's avatar Francisco Souza Committed by Nigel Tao

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
parent 81dbec12
......@@ -14,6 +14,7 @@ RAWHTML=\
articles/json_and_go.rawhtml\
articles/json_rpc_tale_of_interfaces.rawhtml\
articles/image_draw.rawhtml\
articles/image_package.rawhtml\
effective_go.rawhtml\
go1.rawhtml\
......
This diff is collapsed.
......@@ -116,7 +116,7 @@ Guided tours of Go programs.
<li><a href="/doc/articles/json_and_go.html">JSON and Go</a> - using the <a href="/pkg/encoding/json/">json</a> package.</li>
<li><a href="/doc/articles/gobs_of_data.html">Gobs of data</a> - the design and use of the <a href="/pkg/encoding/gob/">gob</a> package.</li>
<li><a href="/doc/articles/laws_of_reflection.html">The Laws of Reflection</a> - the fundamentals of the <a href="/pkg/reflect/">reflect</a> package.</li>
<li><a href="http://blog.golang.org/2011/09/go-image-package.html">The Go image package</a> - the fundamentals of the <a href="/pkg/image/">image</a> package.</li>
<li><a href="/doc/articles/image_package.html">The Go image package</a> - the fundamentals of the <a href="/pkg/image/">image</a> package.</li>
<li><a href="/doc/articles/image_draw.html">The Go image/draw package</a> - the fundamentals of the <a href="/pkg/image/draw/">image/draw</a> package.</li>
</ul>
......
// 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)
}
// 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
}
// 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
}
// 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}
}
// 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))
}
// 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"
......@@ -18,7 +18,7 @@
// initialization side effects.
//
// See "The Go image package" for more details:
// http://blog.golang.org/2011/09/go-image-package.html
// http://golang.org/doc/articles/image_package.html
package image
import (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment