# package image
`import "image"`
image实现了基本的2D图片库。
基本接口叫作Image。图片的色彩定义在image/color包。
Image接口可以通过调用如NewRGBA和NewPaletted函数等获得;也可以通过调用Decode函数解码包含GIF、JPEG或PNG格式图像数据的输入流获得。解码任何具体图像类型之前都必须注册对应类型的解码函数。注册过程一般是作为包初始化的副作用,放在包的init函数里。因此,要解码PNG图像,只需在程序的main包里嵌入如下代码:
```
import _ "image/png"
```
\_表示导入包但不使用包中的变量/函数/类型,只是为了包初始化函数的副作用。
参见[http://golang.org/doc/articles/image_package.html](http://golang.org/doc/articles/image_package.html)
Example
```
// This example demonstrates decoding a JPEG image and examining its pixels.
package image_test
import (
"encoding/base64"
"fmt"
"image"
"log"
"strings"
// Package image/jpeg is not used explicitly in the code below,
// but is imported for its initialization side-effect, which allows
// image.Decode to understand JPEG formatted images. Uncomment these
// two lines to also understand GIF and PNG images:
// _ "image/gif"
// _ "image/png"
_ "image/jpeg"
)
func Example() {
// Decode the JPEG data. If reading from file, create a reader with
//
// reader, err := os.Open("testdata/video-001.q50.420.jpeg")
// if err != nil {
// log.Fatal(err)
// }
// defer reader.Close()
reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data))
m, _, err := image.Decode(reader)
if err != nil {
log.Fatal(err)
}
bounds := m.Bounds()
// Calculate a 16-bin histogram for m's red, green, blue and alpha components.
//
// An image's bounds do not necessarily start at (0, 0), so the two loops start
// at bounds.Min.Y and bounds.Min.X. Looping over Y first and X second is more
// likely to result in better memory access patterns than X first and Y second.
var histogram [16][4]int
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, a := m.At(x, y).RGBA()
// A color's RGBA method returns values in the range [0, 65535].
// Shifting by 12 reduces this to the range [0, 15].
histogram[r>>12][0]++
histogram[g>>12][1]++
histogram[b>>12][2]++
histogram[a>>12][3]++
}
}
// Print the results.
fmt.Printf("%-14s %6s %6s %6s %6s\n", "bin", "red", "green", "blue", "alpha")
for i, x := range histogram {
fmt.Printf("0x%04x-0x%04x: %6d %6d %6d %6d\n", i<<12, (i+1)<<12-1, x[0], x[1], x[2], x[3])
}
// Output:
// bin red green blue alpha
// 0x0000-0x0fff: 353 759 7228 0
// 0x1000-0x1fff: 629 2944 1036 0
// 0x2000-0x2fff: 1075 2319 984 0
// 0x3000-0x3fff: 838 2291 988 0
// 0x4000-0x4fff: 540 1302 542 0
// 0x5000-0x5fff: 319 971 263 0
// 0x6000-0x6fff: 316 377 178 0
// 0x7000-0x7fff: 581 280 216 0
// 0x8000-0x8fff: 3457 228 274 0
// 0x9000-0x9fff: 2294 237 334 0
// 0xa000-0xafff: 938 283 370 0
// 0xb000-0xbfff: 322 338 401 0
// 0xc000-0xcfff: 229 386 295 0
// 0xd000-0xdfff: 263 416 281 0
// 0xe000-0xefff: 538 433 312 0
// 0xf000-0xffff: 2758 1886 1748 15450
}
const data = `
/9j/4AAQSkZJRgABAQIAHAAcAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdA
SFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2Nj
Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCABnAJYDASIAAhEBAxEB/8QA
HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIh
MUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVW
V1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG
x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQF
BgcICQoL/8QAtREAAgEC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ysmQMZAAwa3a5j4ftu0ByP+fh/5CulkLLG7INzhSVHqe1Fh3uOoqn9qQQxyhndmHIxwOmSR2xQ13KD
KoiBZOV9JBnt707MVy5RWdNdy7wRGf3bfMinnO1jg+vY03WXLaJO3mhQ20b0zwpYf0qlG7S7icrJs08U
VwumgC+YiQyeVtZH567hzj8aSL949oGhE/2v5pJCDkksQwBHC4/+vXQ8LZ2uYxxCavY7us/xCcaBfn0h
b+VP0bnSrb94ZMJgOecj1rl/GfidUE2k2gy5+SeQjgA/wj3rlas2jdao48qrjLAGkSKPk4Gc1WMj92I+
lIJnU8OfxPWo5inBokmtQTmM4OOh71b0q6vbFmWCbaxHyqQGAP0PT8KhSTzVyo5ocSKA5VfTOTmqsmRd
pl99XjPzThzK3zOeOSeveirNmkgg/fIpYsTkYORxRXmzlTjJqx6EVUcU7mhkKCzdAK59QI9zYxtG1fYU
UVtgtmY4nZEa8Ak9aqFv3rfSiiu1nMeifDv/AJF+T/r4f+QrqqKKQwzQenNFFMCOKFIgNuThdoJ5OPSk
ubeK6t3gnXdG4wwziiii/UTKMOg6dbzJLFE4dSCP3rEdeOM8805tDsGMvySgSsS6rM6gk9eAcUUVftZt
3uyVGNthuq3Eei6DK8H7sRR7YuMgHtXkc8rzTNLM26RyWY+p70UVnLY0iEsUipG7rhZBlDkc1HgYoorM
0HwyBXGeRjmrcUhMg2ghezd//rUUVcTKW5s2jZtY/QDaOKKKK8ip8bPRj8KP/9k=
`
```
## Index
* [Variables](#pkg-variables)
* [type Image](#Image)
* [func Decode(r io.Reader) (Image, string, error)](#Decode)
* [type PalettedImage](#PalettedImage)
* [type Config](#Config)
* [func DecodeConfig(r io.Reader) (Config, string, error)](#DecodeConfig)
* [func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))](#RegisterFormat)
* [type Point](#Point)
* [func Pt(X, Y int) Point](#Pt)
* [func (p Point) Eq(q Point) bool](#Point.Eq)
* [func (p Point) Add(q Point) Point](#Point.Add)
* [func (p Point) Sub(q Point) Point](#Point.Sub)
* [func (p Point) Mul(k int) Point](#Point.Mul)
* [func (p Point) Div(k int) Point](#Point.Div)
* [func (p Point) In(r Rectangle) bool](#Point.In)
* [func (p Point) Mod(r Rectangle) Point](#Point.Mod)
* [func (p Point) String() string](#Point.String)
* [type Rectangle](#Rectangle)
* [func Rect(x0, y0, x1, y1 int) Rectangle](#Rect)
* [func (r Rectangle) Canon() Rectangle](#Rectangle.Canon)
* [func (r Rectangle) Dx() int](#Rectangle.Dx)
* [func (r Rectangle) Dy() int](#Rectangle.Dy)
* [func (r Rectangle) Size() Point](#Rectangle.Size)
* [func (r Rectangle) Empty() bool](#Rectangle.Empty)
* [func (r Rectangle) Eq(s Rectangle) bool](#Rectangle.Eq)
* [func (r Rectangle) In(s Rectangle) bool](#Rectangle.In)
* [func (r Rectangle) Overlaps(s Rectangle) bool](#Rectangle.Overlaps)
* [func (r Rectangle) Add(p Point) Rectangle](#Rectangle.Add)
* [func (r Rectangle) Sub(p Point) Rectangle](#Rectangle.Sub)
* [func (r Rectangle) Intersect(s Rectangle) Rectangle](#Rectangle.Intersect)
* [func (r Rectangle) Union(s Rectangle) Rectangle](#Rectangle.Union)
* [func (r Rectangle) Inset(n int) Rectangle](#Rectangle.Inset)
* [func (r Rectangle) String() string](#Rectangle.String)
* [type Uniform](#Uniform)
* [func NewUniform(c color.Color) \*Uniform](#NewUniform)
* [func (c \*Uniform) At(x, y int) color.Color](#Uniform.At)
* [func (c \*Uniform) Bounds() Rectangle](#Uniform.Bounds)
* [func (c \*Uniform) ColorModel() color.Model](#Uniform.ColorModel)
* [func (c \*Uniform) Convert(color.Color) color.Color](#Uniform.Convert)
* [func (c \*Uniform) Opaque() bool](#Uniform.Opaque)
* [func (c \*Uniform) RGBA() (r, g, b, a uint32)](#Uniform.RGBA)
* [type Alpha](#Alpha)
* [func NewAlpha(r Rectangle) \*Alpha](#NewAlpha)
* [func (p \*Alpha) At(x, y int) color.Color](#Alpha.At)
* [func (p \*Alpha) Bounds() Rectangle](#Alpha.Bounds)
* [func (p \*Alpha) ColorModel() color.Model](#Alpha.ColorModel)
* [func (p \*Alpha) Opaque() bool](#Alpha.Opaque)
* [func (p \*Alpha) PixOffset(x, y int) int](#Alpha.PixOffset)
* [func (p \*Alpha) Set(x, y int, c color.Color)](#Alpha.Set)
* [func (p \*Alpha) SetAlpha(x, y int, c color.Alpha)](#Alpha.SetAlpha)
* [func (p \*Alpha) SubImage(r Rectangle) Image](#Alpha.SubImage)
* [type Alpha16](#Alpha16)
* [func NewAlpha16(r Rectangle) \*Alpha16](#NewAlpha16)
* [func (p \*Alpha16) At(x, y int) color.Color](#Alpha16.At)
* [func (p \*Alpha16) Bounds() Rectangle](#Alpha16.Bounds)
* [func (p \*Alpha16) ColorModel() color.Model](#Alpha16.ColorModel)
* [func (p \*Alpha16) Opaque() bool](#Alpha16.Opaque)
* [func (p \*Alpha16) PixOffset(x, y int) int](#Alpha16.PixOffset)
* [func (p \*Alpha16) Set(x, y int, c color.Color)](#Alpha16.Set)
* [func (p \*Alpha16) SetAlpha16(x, y int, c color.Alpha16)](#Alpha16.SetAlpha16)
* [func (p \*Alpha16) SubImage(r Rectangle) Image](#Alpha16.SubImage)
* [type Gray](#Gray)
* [func NewGray(r Rectangle) \*Gray](#NewGray)
* [func (p \*Gray) At(x, y int) color.Color](#Gray.At)
* [func (p \*Gray) Bounds() Rectangle](#Gray.Bounds)
* [func (p \*Gray) ColorModel() color.Model](#Gray.ColorModel)
* [func (p \*Gray) Opaque() bool](#Gray.Opaque)
* [func (p \*Gray) PixOffset(x, y int) int](#Gray.PixOffset)
* [func (p \*Gray) Set(x, y int, c color.Color)](#Gray.Set)
* [func (p \*Gray) SetGray(x, y int, c color.Gray)](#Gray.SetGray)
* [func (p \*Gray) SubImage(r Rectangle) Image](#Gray.SubImage)
* [type Gray16](#Gray16)
* [func NewGray16(r Rectangle) \*Gray16](#NewGray16)
* [func (p \*Gray16) At(x, y int) color.Color](#Gray16.At)
* [func (p \*Gray16) Bounds() Rectangle](#Gray16.Bounds)
* [func (p \*Gray16) ColorModel() color.Model](#Gray16.ColorModel)
* [func (p \*Gray16) Opaque() bool](#Gray16.Opaque)
* [func (p \*Gray16) PixOffset(x, y int) int](#Gray16.PixOffset)
* [func (p \*Gray16) Set(x, y int, c color.Color)](#Gray16.Set)
* [func (p \*Gray16) SetGray16(x, y int, c color.Gray16)](#Gray16.SetGray16)
* [func (p \*Gray16) SubImage(r Rectangle) Image](#Gray16.SubImage)
* [type RGBA](#RGBA)
* [func NewRGBA(r Rectangle) \*RGBA](#NewRGBA)
* [func (p \*RGBA) At(x, y int) color.Color](#RGBA.At)
* [func (p \*RGBA) Bounds() Rectangle](#RGBA.Bounds)
* [func (p \*RGBA) ColorModel() color.Model](#RGBA.ColorModel)
* [func (p \*RGBA) Opaque() bool](#RGBA.Opaque)
* [func (p \*RGBA) PixOffset(x, y int) int](#RGBA.PixOffset)
* [func (p \*RGBA) Set(x, y int, c color.Color)](#RGBA.Set)
* [func (p \*RGBA) SetRGBA(x, y int, c color.RGBA)](#RGBA.SetRGBA)
* [func (p \*RGBA) SubImage(r Rectangle) Image](#RGBA.SubImage)
* [type RGBA64](#RGBA64)
* [func NewRGBA64(r Rectangle) \*RGBA64](#NewRGBA64)
* [func (p \*RGBA64) At(x, y int) color.Color](#RGBA64.At)
* [func (p \*RGBA64) Bounds() Rectangle](#RGBA64.Bounds)
* [func (p \*RGBA64) ColorModel() color.Model](#RGBA64.ColorModel)
* [func (p \*RGBA64) Opaque() bool](#RGBA64.Opaque)
* [func (p \*RGBA64) PixOffset(x, y int) int](#RGBA64.PixOffset)
* [func (p \*RGBA64) Set(x, y int, c color.Color)](#RGBA64.Set)
* [func (p \*RGBA64) SetRGBA64(x, y int, c color.RGBA64)](#RGBA64.SetRGBA64)
* [func (p \*RGBA64) SubImage(r Rectangle) Image](#RGBA64.SubImage)
* [type NRGBA](#NRGBA)
* [func NewNRGBA(r Rectangle) \*NRGBA](#NewNRGBA)
* [func (p \*NRGBA) At(x, y int) color.Color](#NRGBA.At)
* [func (p \*NRGBA) Bounds() Rectangle](#NRGBA.Bounds)
* [func (p \*NRGBA) ColorModel() color.Model](#NRGBA.ColorModel)
* [func (p \*NRGBA) Opaque() bool](#NRGBA.Opaque)
* [func (p \*NRGBA) PixOffset(x, y int) int](#NRGBA.PixOffset)
* [func (p \*NRGBA) Set(x, y int, c color.Color)](#NRGBA.Set)
* [func (p \*NRGBA) SetNRGBA(x, y int, c color.NRGBA)](#NRGBA.SetNRGBA)
* [func (p \*NRGBA) SubImage(r Rectangle) Image](#NRGBA.SubImage)
* [type NRGBA64](#NRGBA64)
* [func NewNRGBA64(r Rectangle) \*NRGBA64](#NewNRGBA64)
* [func (p \*NRGBA64) At(x, y int) color.Color](#NRGBA64.At)
* [func (p \*NRGBA64) Bounds() Rectangle](#NRGBA64.Bounds)
* [func (p \*NRGBA64) ColorModel() color.Model](#NRGBA64.ColorModel)
* [func (p \*NRGBA64) Opaque() bool](#NRGBA64.Opaque)
* [func (p \*NRGBA64) PixOffset(x, y int) int](#NRGBA64.PixOffset)
* [func (p \*NRGBA64) Set(x, y int, c color.Color)](#NRGBA64.Set)
* [func (p \*NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)](#NRGBA64.SetNRGBA64)
* [func (p \*NRGBA64) SubImage(r Rectangle) Image](#NRGBA64.SubImage)
* [type Paletted](#Paletted)
* [func NewPaletted(r Rectangle, p color.Palette) \*Paletted](#NewPaletted)
* [func (p \*Paletted) At(x, y int) color.Color](#Paletted.At)
* [func (p \*Paletted) Bounds() Rectangle](#Paletted.Bounds)
* [func (p \*Paletted) ColorIndexAt(x, y int) uint8](#Paletted.ColorIndexAt)
* [func (p \*Paletted) ColorModel() color.Model](#Paletted.ColorModel)
* [func (p \*Paletted) Opaque() bool](#Paletted.Opaque)
* [func (p \*Paletted) PixOffset(x, y int) int](#Paletted.PixOffset)
* [func (p \*Paletted) Set(x, y int, c color.Color)](#Paletted.Set)
* [func (p \*Paletted) SetColorIndex(x, y int, index uint8)](#Paletted.SetColorIndex)
* [func (p \*Paletted) SubImage(r Rectangle) Image](#Paletted.SubImage)
* [type YCbCrSubsampleRatio](#YCbCrSubsampleRatio)
* [func (s YCbCrSubsampleRatio) String() string](#YCbCrSubsampleRatio.String)
* [type YCbCr](#YCbCr)
* [func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) \*YCbCr](#NewYCbCr)
* [func (p \*YCbCr) At(x, y int) color.Color](#YCbCr.At)
* [func (p \*YCbCr) Bounds() Rectangle](#YCbCr.Bounds)
* [func (p \*YCbCr) COffset(x, y int) int](#YCbCr.COffset)
* [func (p \*YCbCr) ColorModel() color.Model](#YCbCr.ColorModel)
* [func (p \*YCbCr) Opaque() bool](#YCbCr.Opaque)
* [func (p \*YCbCr) SubImage(r Rectangle) Image](#YCbCr.SubImage)
* [func (p \*YCbCr) YOffset(x, y int) int](#YCbCr.YOffset)
### Examples
* [package](#example-package)
## Variables
```
var (
// Black是一个完全不透明的面积无限大的黑色图像
Black = NewUniform(color.Black)
// White是一个完全不透明的面积无限大的白色图像
White = NewUniform(color.White)
// Transparent是一个完全透明的面积无限大的图像
Transparent = NewUniform(color.Transparent)
// Opaque是一个完全不透明的面积无限大的图像
Opaque = NewUniform(color.Opaque)
)
```
```
var ErrFormat = errors.New("image: unknown format")
```
ErrFormat说明解码时遇到了未知的格式。
## type [Image](https://github.com/golang/go/blob/master/src/image/image.go#L36 "View Source")
```
type Image interface {
// ColorModel方法返回图像的色彩模型
ColorModel() color.Model
// Bounds方法返回图像的范围,范围不一定包括点(0, 0)
Bounds() Rectangle
// At方法返回(x, y)位置的色彩
// At(Bounds().Min.X, Bounds().Min.Y)返回网格左上角像素的色彩
// At(Bounds().Max.X-1, Bounds().Max.Y-1) 返回网格右下角像素的色彩
At(x, y int) color.Color
}
```
Image接口表示一个采用某色彩模型的颜色构成的有限矩形网格(即一幅图像)。
### func [Decode](https://github.com/golang/go/blob/master/src/image/format.go#L78 "View Source")
```
func Decode(r io.Reader) (Image, string, error)
```
DecodeConfig函数解码并返回一个采用某种已注册格式编码的图像。字符串返回值是该格式注册时的名字。格式一般是在该编码格式的包的init函数中注册的。
## type [PalettedImage](https://github.com/golang/go/blob/master/src/image/image.go#L53 "View Source")
```
type PalettedImage interface {
// ColorIndexAt方法返回(x, y)位置的像素的(调色板)索引
ColorIndexAt(x, y int) uint8
Image
}
```
PalettedImage接口代表一幅图像,它的像素可能来自一个有限的调色板。
如果有对象m满足PalettedImage接口,且m.ColorModel()返回的color.Model接口底层为一个Palette类型值(记为p),则m.At(x, y)返回值应等于p[m.ColorIndexAt(x, y)]。如果m的色彩模型不是Palette,则ColorIndexAt的行为是不确定的。
## type [Config](https://github.com/golang/go/blob/master/src/image/image.go#L29 "View Source")
```
type Config struct {
ColorModel color.Model
Width, Height int
}
```
Config保管图像的色彩模型和尺寸信息。
### func [DecodeConfig](https://github.com/golang/go/blob/master/src/image/format.go#L92 "View Source")
```
func DecodeConfig(r io.Reader) (Config, string, error)
```
DecodeConfig函数解码并返回一个采用某种已注册格式编码的图像的色彩模型和尺寸。字符串返回值是该格式注册时的名字。格式一般是在该编码格式的包的init函数中注册的。
## func [RegisterFormat](https://github.com/golang/go/blob/master/src/image/format.go#L32 "View Source")
```
func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))
```
RegisterFormat注册一个供Decode函数使用的图片格式。name是格式的名字,如"jpeg"或"png";magic是该格式编码的魔术前缀,该字符串可以包含"?"通配符,每个通配符匹配一个字节;decode函数用于解码图片;decodeConfig函数只解码图片的配置。
## type [Point](https://github.com/golang/go/blob/master/src/image/geom.go#L12 "View Source")
```
type Point struct {
X, Y int
}
```
Point是X, Y坐标对。坐标轴是向右(X)向下(Y)的。既可以表示点,也可以表示向量。
```
var ZP Point
```
ZP是原点。
### func [Pt](https://github.com/golang/go/blob/master/src/image/geom.go#L72 "View Source")
```
func Pt(X, Y int) Point
```
返回Point{X , Y}
### func (Point) [Eq](https://github.com/golang/go/blob/master/src/image/geom.go#L64 "View Source")
```
func (p Point) Eq(q Point) bool
```
报告p和q是否相同。
### func (Point) [Add](https://github.com/golang/go/blob/master/src/image/geom.go#L22 "View Source")
```
func (p Point) Add(q Point) Point
```
返回点Point{p.X+q.X, p.Y+q.Y}
### func (Point) [Sub](https://github.com/golang/go/blob/master/src/image/geom.go#L27 "View Source")
```
func (p Point) Sub(q Point) Point
```
返回点Point{p.X-q.X, p.Y-q.Y}
### func (Point) [Mul](https://github.com/golang/go/blob/master/src/image/geom.go#L32 "View Source")
```
func (p Point) Mul(k int) Point
```
返回点Point{p.X\*k, p.Y\*k}
### func (Point) [Div](https://github.com/golang/go/blob/master/src/image/geom.go#L37 "View Source")
```
func (p Point) Div(k int) Point
```
返回点Point{p.X/k, p.Y/k }
### func (Point) [In](https://github.com/golang/go/blob/master/src/image/geom.go#L42 "View Source")
```
func (p Point) In(r Rectangle) bool
```
报告p是否在r范围内。
### func (Point) [Mod](https://github.com/golang/go/blob/master/src/image/geom.go#L49 "View Source")
```
func (p Point) Mod(r Rectangle) Point
```
返回r范围内的某点q,满足p.X-q.X是r宽度的倍数,p.Y-q.Y是r高度的倍数。
### func (Point) [String](https://github.com/golang/go/blob/master/src/image/geom.go#L17 "View Source")
```
func (p Point) String() string
```
返回p的字符串表示。格式为"(3,4)"
## type [Rectangle](https://github.com/golang/go/blob/master/src/image/geom.go#L80 "View Source")
```
type Rectangle struct {
Min, Max Point
}
```
Rectangle代表一个矩形。该矩形包含所有满足Min.X <= X < Max.X且Min.Y <= Y < Max.Y的点。如果两个字段满足Min.X <= Max.X且Min.Y <= Max.Y,就称该实例为规范格式的。矩形的方法,当输入是规范格式时,总是返回规范格式的输出。
```
var ZR Rectangle
```
ZR是矩形的零值。
### func [Rect](https://github.com/golang/go/blob/master/src/image/geom.go#L226 "View Source")
```
func Rect(x0, y0, x1, y1 int) Rectangle
```
返回一个矩形Rectangle{Pt(x0, y0), Pt(x1, y1)}。
### func (Rectangle) [Canon](https://github.com/golang/go/blob/master/src/image/geom.go#L212 "View Source")
```
func (r Rectangle) Canon() Rectangle
```
返回矩形的规范版本(左上&右下),方法必要时会交换坐标的最大值和最小值。
### func (Rectangle) [Dx](https://github.com/golang/go/blob/master/src/image/geom.go#L90 "View Source")
```
func (r Rectangle) Dx() int
```
返回r的宽度。
### func (Rectangle) [Dy](https://github.com/golang/go/blob/master/src/image/geom.go#L95 "View Source")
```
func (r Rectangle) Dy() int
```
返回r的高度。
### func (Rectangle) [Size](https://github.com/golang/go/blob/master/src/image/geom.go#L100 "View Source")
```
func (r Rectangle) Size() Point
```
返回r的宽度w和高度h构成的点Point{w, h}。
### func (Rectangle) [Empty](https://github.com/golang/go/blob/master/src/image/geom.go#L183 "View Source")
```
func (r Rectangle) Empty() bool
```
报告矩形是否为空矩形。(即内部不包含点的矩形)
### func (Rectangle) [Eq](https://github.com/golang/go/blob/master/src/image/geom.go#L188 "View Source")
```
func (r Rectangle) Eq(s Rectangle) bool
```
报告两个矩形是否相同。
### func (Rectangle) [In](https://github.com/golang/go/blob/master/src/image/geom.go#L200 "View Source")
```
func (r Rectangle) In(s Rectangle) bool
```
如果r包含的所有点都在s内,则返回真;否则返回假。
### func (Rectangle) [Overlaps](https://github.com/golang/go/blob/master/src/image/geom.go#L194 "View Source")
```
func (r Rectangle) Overlaps(s Rectangle) bool
```
如果r和s有非空的交集,则返回真;否则返回假。
### func (Rectangle) [Add](https://github.com/golang/go/blob/master/src/image/geom.go#L108 "View Source")
```
func (r Rectangle) Add(p Point) Rectangle
```
返回矩形按p(作为向量)平移后的新矩形。
### func (Rectangle) [Sub](https://github.com/golang/go/blob/master/src/image/geom.go#L116 "View Source")
```
func (r Rectangle) Sub(p Point) Rectangle
```
返回矩形按p(作为向量)反向平移后的新矩形。
### func (Rectangle) [Intersect](https://github.com/golang/go/blob/master/src/image/geom.go#L146 "View Source")
```
func (r Rectangle) Intersect(s Rectangle) Rectangle
```
返回两个矩形的交集矩形(同时被r和s包含的最大矩形);如果r和s没有重叠会返回Rectangle零值。
### func (Rectangle) [Union](https://github.com/golang/go/blob/master/src/image/geom.go#L166 "View Source")
```
func (r Rectangle) Union(s Rectangle) Rectangle
```
返回同时包含r和s的最小矩形。
### func (Rectangle) [Inset](https://github.com/golang/go/blob/master/src/image/geom.go#L126 "View Source")
```
func (r Rectangle) Inset(n int) Rectangle
```
返回去掉矩形四周宽度n的框的矩形,n可为负数。如果n过大将返回靠近r中心位置的空矩形。
### func (Rectangle) [String](https://github.com/golang/go/blob/master/src/image/geom.go#L85 "View Source")
```
func (r Rectangle) String() string
```
返回矩形的字符串表示,格式为"(3,4)-(6,5)"。
## type [Uniform](https://github.com/golang/go/blob/master/src/image/names.go#L24 "View Source")
```
type Uniform struct {
C color.Color
}
```
Uniform类型代表一块面积无限大的具有同一色彩的图像。它实现了color.Color、color.Model和Image等接口。
### func [NewUniform](https://github.com/golang/go/blob/master/src/image/names.go#L50 "View Source")
```
func NewUniform(c color.Color) *Uniform
```
### func (\*Uniform) [At](https://github.com/golang/go/blob/master/src/image/names.go#L42 "View Source")
```
func (c *Uniform) At(x, y int) color.Color
```
### func (\*Uniform) [Bounds](https://github.com/golang/go/blob/master/src/image/names.go#L40 "View Source")
```
func (c *Uniform) Bounds() Rectangle
```
### func (\*Uniform) [ColorModel](https://github.com/golang/go/blob/master/src/image/names.go#L32 "View Source")
```
func (c *Uniform) ColorModel() color.Model
```
### func (\*Uniform) [Convert](https://github.com/golang/go/blob/master/src/image/names.go#L36 "View Source")
```
func (c *Uniform) Convert(color.Color) color.Color
```
### func (\*Uniform) [Opaque](https://github.com/golang/go/blob/master/src/image/names.go#L45 "View Source")
```
func (c *Uniform) Opaque() bool
```
Opaque方法扫描整个图像并报告该图像是否是完全不透明的。
### func (\*Uniform) [RGBA](https://github.com/golang/go/blob/master/src/image/names.go#L28 "View Source")
```
func (c *Uniform) RGBA() (r, g, b, a uint32)
```
## type [Alpha](https://github.com/golang/go/blob/master/src/image/image.go#L466 "View Source")
```
type Alpha struct {
// Pix保管图像的像素,内容为alpha通道值(即透明度)。
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
Alpha类型代表一幅内存中的图像,其At方法返回color.Alpha类型的值。
### func [NewAlpha](https://github.com/golang/go/blob/master/src/image/image.go#L547 "View Source")
```
func NewAlpha(r Rectangle) *Alpha
```
NewAlpha函数创建并返回一个具有指定宽度和高度的Alpha。
### func (\*Alpha) [At](https://github.com/golang/go/blob/master/src/image/image.go#L480 "View Source")
```
func (p *Alpha) At(x, y int) color.Color
```
### func (\*Alpha) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L478 "View Source")
```
func (p *Alpha) Bounds() Rectangle
```
### func (\*Alpha) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L476 "View Source")
```
func (p *Alpha) ColorModel() color.Model
```
### func (\*Alpha) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L529 "View Source")
```
func (p *Alpha) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*Alpha) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L490 "View Source")
```
func (p *Alpha) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*Alpha) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L494 "View Source")
```
func (p *Alpha) Set(x, y int, c color.Color)
```
### func (\*Alpha) [SetAlpha](https://github.com/golang/go/blob/master/src/image/image.go#L502 "View Source")
```
func (p *Alpha) SetAlpha(x, y int, c color.Alpha)
```
### func (\*Alpha) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L512 "View Source")
```
func (p *Alpha) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [Alpha16](https://github.com/golang/go/blob/master/src/image/image.go#L554 "View Source")
```
type Alpha16 struct {
// Pix保管图像的像素,内容为alpha通道值(即透明度,大端在前的格式)。
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
Alpha16类型代表一幅内存中的图像,其At方法返回color.Alpha16类型的值。
### func [NewAlpha16](https://github.com/golang/go/blob/master/src/image/image.go#L638 "View Source")
```
func NewAlpha16(r Rectangle) *Alpha16
```
NewAlpha16函数创建并返回一个具有指定范围的Alpha16。
### func (\*Alpha16) [At](https://github.com/golang/go/blob/master/src/image/image.go#L568 "View Source")
```
func (p *Alpha16) At(x, y int) color.Color
```
### func (\*Alpha16) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L566 "View Source")
```
func (p *Alpha16) Bounds() Rectangle
```
### func (\*Alpha16) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L564 "View Source")
```
func (p *Alpha16) ColorModel() color.Model
```
### func (\*Alpha16) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L620 "View Source")
```
func (p *Alpha16) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*Alpha16) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L578 "View Source")
```
func (p *Alpha16) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*Alpha16) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L582 "View Source")
```
func (p *Alpha16) Set(x, y int, c color.Color)
```
### func (\*Alpha16) [SetAlpha16](https://github.com/golang/go/blob/master/src/image/image.go#L592 "View Source")
```
func (p *Alpha16) SetAlpha16(x, y int, c color.Alpha16)
```
### func (\*Alpha16) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L603 "View Source")
```
func (p *Alpha16) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [Gray](https://github.com/golang/go/blob/master/src/image/image.go#L645 "View Source")
```
type Gray struct {
// Pix保管图像的像素,内容为灰度。
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
Gray类型代表一幅内存中的图像,其At方法返回color.Gray类型的值。
### func [NewGray](https://github.com/golang/go/blob/master/src/image/image.go#L713 "View Source")
```
func NewGray(r Rectangle) *Gray
```
NewGray函数创建并返回一个具有指定范围的Gray。
### func (\*Gray) [At](https://github.com/golang/go/blob/master/src/image/image.go#L659 "View Source")
```
func (p *Gray) At(x, y int) color.Color
```
### func (\*Gray) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L657 "View Source")
```
func (p *Gray) Bounds() Rectangle
```
### func (\*Gray) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L655 "View Source")
```
func (p *Gray) ColorModel() color.Model
```
### func (\*Gray) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L708 "View Source")
```
func (p *Gray) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*Gray) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L669 "View Source")
```
func (p *Gray) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*Gray) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L673 "View Source")
```
func (p *Gray) Set(x, y int, c color.Color)
```
### func (\*Gray) [SetGray](https://github.com/golang/go/blob/master/src/image/image.go#L681 "View Source")
```
func (p *Gray) SetGray(x, y int, c color.Gray)
```
### func (\*Gray) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L691 "View Source")
```
func (p *Gray) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [Gray16](https://github.com/golang/go/blob/master/src/image/image.go#L720 "View Source")
```
type Gray16 struct {
// Pix保管图像的像素,内容为灰度(大端在前的格式)。
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
Gray16类型代表一幅内存中的图像,其At方法返回color.Gray16类型的值。
### func [NewGray16](https://github.com/golang/go/blob/master/src/image/image.go#L791 "View Source")
```
func NewGray16(r Rectangle) *Gray16
```
NewGray16函数创建并返回一个具有指定范围的Gray16。
### func (\*Gray16) [At](https://github.com/golang/go/blob/master/src/image/image.go#L734 "View Source")
```
func (p *Gray16) At(x, y int) color.Color
```
### func (\*Gray16) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L732 "View Source")
```
func (p *Gray16) Bounds() Rectangle
```
### func (\*Gray16) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L730 "View Source")
```
func (p *Gray16) ColorModel() color.Model
```
### func (\*Gray16) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L786 "View Source")
```
func (p *Gray16) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*Gray16) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L744 "View Source")
```
func (p *Gray16) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*Gray16) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L748 "View Source")
```
func (p *Gray16) Set(x, y int, c color.Color)
```
### func (\*Gray16) [SetGray16](https://github.com/golang/go/blob/master/src/image/image.go#L758 "View Source")
```
func (p *Gray16) SetGray16(x, y int, c color.Gray16)
```
### func (\*Gray16) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L769 "View Source")
```
func (p *Gray16) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [RGBA](https://github.com/golang/go/blob/master/src/image/image.go#L60 "View Source")
```
type RGBA struct {
// Pix保管图像的像素色彩信息,顺序为R, G, B, A
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
RGBA类型代表一幅内存中的图像,其At方法返回color.RGBA类型的值。
### func [NewRGBA](https://github.com/golang/go/blob/master/src/image/image.go#L148 "View Source")
```
func NewRGBA(r Rectangle) *RGBA
```
NewRGBA函数创建并返回一个具有指定范围的RGBA。
### func (\*RGBA) [At](https://github.com/golang/go/blob/master/src/image/image.go#L74 "View Source")
```
func (p *RGBA) At(x, y int) color.Color
```
### func (\*RGBA) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L72 "View Source")
```
func (p *RGBA) Bounds() Rectangle
```
### func (\*RGBA) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L70 "View Source")
```
func (p *RGBA) ColorModel() color.Model
```
### func (\*RGBA) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L130 "View Source")
```
func (p *RGBA) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*RGBA) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L84 "View Source")
```
func (p *RGBA) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*RGBA) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L88 "View Source")
```
func (p *RGBA) Set(x, y int, c color.Color)
```
### func (\*RGBA) [SetRGBA](https://github.com/golang/go/blob/master/src/image/image.go#L100 "View Source")
```
func (p *RGBA) SetRGBA(x, y int, c color.RGBA)
```
### func (\*RGBA) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L113 "View Source")
```
func (p *RGBA) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [RGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L155 "View Source")
```
type RGBA64 struct {
// Pix保管图像的像素色彩信息,顺序为R, G, B, A(每个值都是大端在前的格式)
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
RGBA64类型代表一幅内存中的图像,其At方法返回color.RGBA64类型的值
### func [NewRGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L256 "View Source")
```
func NewRGBA64(r Rectangle) *RGBA64
```
NewRGBA64函数创建并返回一个具有指定范围的RGBA64
### func (\*RGBA64) [At](https://github.com/golang/go/blob/master/src/image/image.go#L169 "View Source")
```
func (p *RGBA64) At(x, y int) color.Color
```
### func (\*RGBA64) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L167 "View Source")
```
func (p *RGBA64) Bounds() Rectangle
```
### func (\*RGBA64) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L165 "View Source")
```
func (p *RGBA64) ColorModel() color.Model
```
### func (\*RGBA64) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L238 "View Source")
```
func (p *RGBA64) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*RGBA64) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L184 "View Source")
```
func (p *RGBA64) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*RGBA64) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L188 "View Source")
```
func (p *RGBA64) Set(x, y int, c color.Color)
```
### func (\*RGBA64) [SetRGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L204 "View Source")
```
func (p *RGBA64) SetRGBA64(x, y int, c color.RGBA64)
```
### func (\*RGBA64) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L221 "View Source")
```
func (p *RGBA64) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [NRGBA](https://github.com/golang/go/blob/master/src/image/image.go#L263 "View Source")
```
type NRGBA struct {
// Pix保管图像的像素色彩信息,顺序为R, G, B, A
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
NRGBA类型代表一幅内存中的图像,其At方法返回color.NRGBA类型的值。
### func [NewNRGBA](https://github.com/golang/go/blob/master/src/image/image.go#L351 "View Source")
```
func NewNRGBA(r Rectangle) *NRGBA
```
NewNRGBA函数创建并返回一个具有指定范围的NRGBA。
### func (\*NRGBA) [At](https://github.com/golang/go/blob/master/src/image/image.go#L277 "View Source")
```
func (p *NRGBA) At(x, y int) color.Color
```
### func (\*NRGBA) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L275 "View Source")
```
func (p *NRGBA) Bounds() Rectangle
```
### func (\*NRGBA) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L273 "View Source")
```
func (p *NRGBA) ColorModel() color.Model
```
### func (\*NRGBA) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L333 "View Source")
```
func (p *NRGBA) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*NRGBA) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L287 "View Source")
```
func (p *NRGBA) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*NRGBA) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L291 "View Source")
```
func (p *NRGBA) Set(x, y int, c color.Color)
```
### func (\*NRGBA) [SetNRGBA](https://github.com/golang/go/blob/master/src/image/image.go#L303 "View Source")
```
func (p *NRGBA) SetNRGBA(x, y int, c color.NRGBA)
```
### func (\*NRGBA) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L316 "View Source")
```
func (p *NRGBA) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [NRGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L358 "View Source")
```
type NRGBA64 struct {
// Pix保管图像的像素色彩信息,顺序为R, G, B, A(每个值都是大端在前的格式)
// 像素(x, y)起始位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
}
```
NRGBA64类型代表一幅内存中的图像,其At方法返回color.NRGBA64类型的值。
### func [NewNRGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L459 "View Source")
```
func NewNRGBA64(r Rectangle) *NRGBA64
```
NewNRGBA64函数创建并返回一个具有指定范围的NRGBA64。
### func (\*NRGBA64) [At](https://github.com/golang/go/blob/master/src/image/image.go#L372 "View Source")
```
func (p *NRGBA64) At(x, y int) color.Color
```
### func (\*NRGBA64) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L370 "View Source")
```
func (p *NRGBA64) Bounds() Rectangle
```
### func (\*NRGBA64) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L368 "View Source")
```
func (p *NRGBA64) ColorModel() color.Model
```
### func (\*NRGBA64) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L441 "View Source")
```
func (p *NRGBA64) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*NRGBA64) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L387 "View Source")
```
func (p *NRGBA64) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*NRGBA64) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L391 "View Source")
```
func (p *NRGBA64) Set(x, y int, c color.Color)
```
### func (\*NRGBA64) [SetNRGBA64](https://github.com/golang/go/blob/master/src/image/image.go#L407 "View Source")
```
func (p *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)
```
### func (\*NRGBA64) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L424 "View Source")
```
func (p *NRGBA64) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [Paletted](https://github.com/golang/go/blob/master/src/image/image.go#L798 "View Source")
```
type Paletted struct {
// Pix保存图像的象素,内容为调色板的索引。
// 像素(x, y)的位置是Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1]
Pix []uint8
// Stride是Pix中每行像素占用的字节数
Stride int
// Rect是图像的范围
Rect Rectangle
// Palette是图像的调色板
Palette color.Palette
}
```
Paletted类型是一幅采用uint8类型索引调色板的内存中的图像。
### func [NewPaletted](https://github.com/golang/go/blob/master/src/image/image.go#L900 "View Source")
```
func NewPaletted(r Rectangle, p color.Palette) *Paletted
```
NewPaletted函数创建并返回一个具有指定范围、调色板的Paletted。
### func (\*Paletted) [At](https://github.com/golang/go/blob/master/src/image/image.go#L814 "View Source")
```
func (p *Paletted) At(x, y int) color.Color
```
### func (\*Paletted) [Bounds](https://github.com/golang/go/blob/master/src/image/image.go#L812 "View Source")
```
func (p *Paletted) Bounds() Rectangle
```
### func (\*Paletted) [ColorIndexAt](https://github.com/golang/go/blob/master/src/image/image.go#L839 "View Source")
```
func (p *Paletted) ColorIndexAt(x, y int) uint8
```
### func (\*Paletted) [ColorModel](https://github.com/golang/go/blob/master/src/image/image.go#L810 "View Source")
```
func (p *Paletted) ColorModel() color.Model
```
### func (\*Paletted) [Opaque](https://github.com/golang/go/blob/master/src/image/image.go#L877 "View Source")
```
func (p *Paletted) Opaque() bool
```
Opaque方法扫描整个图像并报告图像是否是完全不透明的。
### func (\*Paletted) [PixOffset](https://github.com/golang/go/blob/master/src/image/image.go#L827 "View Source")
```
func (p *Paletted) PixOffset(x, y int) int
```
PixOffset方法返回像素(x, y)的数据起始位置在Pix字段的偏移量/索引。
### func (\*Paletted) [Set](https://github.com/golang/go/blob/master/src/image/image.go#L831 "View Source")
```
func (p *Paletted) Set(x, y int, c color.Color)
```
### func (\*Paletted) [SetColorIndex](https://github.com/golang/go/blob/master/src/image/image.go#L847 "View Source")
```
func (p *Paletted) SetColorIndex(x, y int, index uint8)
```
### func (\*Paletted) [SubImage](https://github.com/golang/go/blob/master/src/image/image.go#L857 "View Source")
```
func (p *Paletted) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
## type [YCbCrSubsampleRatio](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L12 "View Source")
```
type YCbCrSubsampleRatio int
```
YcbCrSubsampleRatio是YCbCr图像的色度二次采样比率。
```
const (
YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iota
YCbCrSubsampleRatio422
YCbCrSubsampleRatio420
YCbCrSubsampleRatio440
)
```
### func (YCbCrSubsampleRatio) [String](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L21 "View Source")
```
func (s YCbCrSubsampleRatio) String() string
```
## type [YCbCr](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L46 "View Source")
```
type YCbCr struct {
Y, Cb, Cr []uint8
YStride int
CStride int
SubsampleRatio YCbCrSubsampleRatio
Rect Rectangle
}
```
YcbCr代表采用Y'CbCr色彩模型的一幅内存中的图像。每个像素都对应一个Y采样,但每个Cb/Cr采样对应多个像素。Ystride是两个垂直相邻的像素之间的Y组分的索引增量。CStride是两个映射到单独的色度采样的垂直相邻的像素之间的Cb/Cr组分的索引增量。虽然不作绝对要求,但Ystride字段和len(Y)一般应为8的倍数,并且:
```
For 4:4:4, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/1.
For 4:2:2, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/2.
For 4:2:0, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/4.
For 4:4:0, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/2.
```
### func [NewYCbCr](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L126 "View Source")
```
func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr
```
NewYCbCr函数创建并返回一个具有指定宽度、高度和二次采样率的YcbCr。
### func (\*YCbCr) [At](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L62 "View Source")
```
func (p *YCbCr) At(x, y int) color.Color
```
### func (\*YCbCr) [Bounds](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L58 "View Source")
```
func (p *YCbCr) Bounds() Rectangle
```
### func (\*YCbCr) [ColorModel](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L54 "View Source")
```
func (p *YCbCr) ColorModel() color.Model
```
### func (\*YCbCr) [Opaque](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L121 "View Source")
```
func (p *YCbCr) Opaque() bool
```
### func (\*YCbCr) [COffset](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L83 "View Source")
```
func (p *YCbCr) COffset(x, y int) int
```
像素(X, Y)的Cb或Cr(色度)组分的数据起始位置在Cb/Cr字段的偏移量/索引。
### func (\*YCbCr) [YOffset](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L77 "View Source")
```
func (p *YCbCr) YOffset(x, y int) int
```
像素(X, Y)的Y(亮度)组分的数据起始位置在Y字段的偏移量/索引。
### func (\*YCbCr) [SubImage](https://github.com/golang/go/blob/master/src/image/ycbcr.go#L98 "View Source")
```
func (p *YCbCr) SubImage(r Rectangle) Image
```
SubImage方法返回代表原图像一部分(r的范围)的新图像。返回值和原图像的像素数据是共用的。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe