Package image

Overview ▾

Package image implements a basic 2-D image library.

基本接口称为图像. 图像包含颜色,这些颜色在图像/颜色包中描述.

通过调用诸如NewRGBA和NewPaletted之类的函数,或者通过在io.Reader上调用Decode来创建Image接口的值,该io.Reader包含诸如GIF,JPEG或PNG格式的图像数据. 解码任何特定的图像格式需要事先注册解码器功能. 通常,注册是自动的,这是初始化该格式文件包的副作用,因此,要解码PNG图像,只需具有

import _ "image/png"

在程序的主程序包中. _表示纯粹出于初始化副作用而导入软件包.

有关更多详细信息,请参见" Go图片包": https : //golang.org/doc/articles/image_package.html

Example

bin               red  green   blue  alpha
0x0000-0x0fff:    364    790   7242      0
0x1000-0x1fff:    645   2967   1039      0
0x2000-0x2fff:   1072   2299    979      0
0x3000-0x3fff:    820   2266    980      0
0x4000-0x4fff:    537   1305    541      0
0x5000-0x5fff:    319    962    261      0
0x6000-0x6fff:    322    375    177      0
0x7000-0x7fff:    601    279    214      0
0x8000-0x8fff:   3478    227    273      0
0x9000-0x9fff:   2260    234    329      0
0xa000-0xafff:    921    282    373      0
0xb000-0xbfff:    321    335    397      0
0xc000-0xcfff:    229    388    298      0
0xd000-0xdfff:    260    414    277      0
0xe000-0xefff:    516    428    298      0
0xf000-0xffff:   2785   1899   1772  15450

示例(DecodeConfig)

Index ▾

Variables
func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))
type Alpha
    func NewAlpha(r Rectangle) *Alpha
    func (p *Alpha) AlphaAt(x, y int) color.Alpha
    func (p *Alpha) At(x, y int) color.Color
    func (p *Alpha) Bounds() Rectangle
    func (p *Alpha) ColorModel() color.Model
    func (p *Alpha) Opaque() bool
    func (p *Alpha) PixOffset(x, y int) int
    func (p *Alpha) Set(x, y int, c color.Color)
    func (p *Alpha) SetAlpha(x, y int, c color.Alpha)
    func (p *Alpha) SubImage(r Rectangle) Image
type Alpha16
    func NewAlpha16(r Rectangle) *Alpha16
    func (p *Alpha16) Alpha16At(x, y int) color.Alpha16
    func (p *Alpha16) At(x, y int) color.Color
    func (p *Alpha16) Bounds() Rectangle
    func (p *Alpha16) ColorModel() color.Model
    func (p *Alpha16) Opaque() bool
    func (p *Alpha16) PixOffset(x, y int) int
    func (p *Alpha16) Set(x, y int, c color.Color)
    func (p *Alpha16) SetAlpha16(x, y int, c color.Alpha16)
    func (p *Alpha16) SubImage(r Rectangle) Image
type CMYK
    func NewCMYK(r Rectangle) *CMYK
    func (p *CMYK) At(x, y int) color.Color
    func (p *CMYK) Bounds() Rectangle
    func (p *CMYK) CMYKAt(x, y int) color.CMYK
    func (p *CMYK) ColorModel() color.Model
    func (p *CMYK) Opaque() bool
    func (p *CMYK) PixOffset(x, y int) int
    func (p *CMYK) Set(x, y int, c color.Color)
    func (p *CMYK) SetCMYK(x, y int, c color.CMYK)
    func (p *CMYK) SubImage(r Rectangle) Image
type Config
    func DecodeConfig(r io.Reader) (Config, string, error)
type Gray
    func NewGray(r Rectangle) *Gray
    func (p *Gray) At(x, y int) color.Color
    func (p *Gray) Bounds() Rectangle
    func (p *Gray) ColorModel() color.Model
    func (p *Gray) GrayAt(x, y int) color.Gray
    func (p *Gray) Opaque() bool
    func (p *Gray) PixOffset(x, y int) int
    func (p *Gray) Set(x, y int, c color.Color)
    func (p *Gray) SetGray(x, y int, c color.Gray)
    func (p *Gray) SubImage(r Rectangle) Image
type Gray16
    func NewGray16(r Rectangle) *Gray16
    func (p *Gray16) At(x, y int) color.Color
    func (p *Gray16) Bounds() Rectangle
    func (p *Gray16) ColorModel() color.Model
    func (p *Gray16) Gray16At(x, y int) color.Gray16
    func (p *Gray16) Opaque() bool
    func (p *Gray16) PixOffset(x, y int) int
    func (p *Gray16) Set(x, y int, c color.Color)
    func (p *Gray16) SetGray16(x, y int, c color.Gray16)
    func (p *Gray16) SubImage(r Rectangle) Image
type Image
    func Decode(r io.Reader) (Image, string, error)
type NRGBA
    func NewNRGBA(r Rectangle) *NRGBA
    func (p *NRGBA) At(x, y int) color.Color
    func (p *NRGBA) Bounds() Rectangle
    func (p *NRGBA) ColorModel() color.Model
    func (p *NRGBA) NRGBAAt(x, y int) color.NRGBA
    func (p *NRGBA) Opaque() bool
    func (p *NRGBA) PixOffset(x, y int) int
    func (p *NRGBA) Set(x, y int, c color.Color)
    func (p *NRGBA) SetNRGBA(x, y int, c color.NRGBA)
    func (p *NRGBA) SubImage(r Rectangle) Image
type NRGBA64
    func NewNRGBA64(r Rectangle) *NRGBA64
    func (p *NRGBA64) At(x, y int) color.Color
    func (p *NRGBA64) Bounds() Rectangle
    func (p *NRGBA64) ColorModel() color.Model
    func (p *NRGBA64) NRGBA64At(x, y int) color.NRGBA64
    func (p *NRGBA64) Opaque() bool
    func (p *NRGBA64) PixOffset(x, y int) int
    func (p *NRGBA64) Set(x, y int, c color.Color)
    func (p *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)
    func (p *NRGBA64) SubImage(r Rectangle) Image
type NYCbCrA
    func NewNYCbCrA(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *NYCbCrA
    func (p *NYCbCrA) AOffset(x, y int) int
    func (p *NYCbCrA) At(x, y int) color.Color
    func (p *NYCbCrA) ColorModel() color.Model
    func (p *NYCbCrA) NYCbCrAAt(x, y int) color.NYCbCrA
    func (p *NYCbCrA) Opaque() bool
    func (p *NYCbCrA) SubImage(r Rectangle) Image
type Paletted
    func NewPaletted(r Rectangle, p color.Palette) *Paletted
    func (p *Paletted) At(x, y int) color.Color
    func (p *Paletted) Bounds() Rectangle
    func (p *Paletted) ColorIndexAt(x, y int) uint8
    func (p *Paletted) ColorModel() color.Model
    func (p *Paletted) Opaque() bool
    func (p *Paletted) PixOffset(x, y int) int
    func (p *Paletted) Set(x, y int, c color.Color)
    func (p *Paletted) SetColorIndex(x, y int, index uint8)
    func (p *Paletted) SubImage(r Rectangle) Image
type PalettedImage
type Point
    func Pt(X, Y int) Point
    func (p Point) Add(q Point) Point
    func (p Point) Div(k int) Point
    func (p Point) Eq(q Point) bool
    func (p Point) In(r Rectangle) bool
    func (p Point) Mod(r Rectangle) Point
    func (p Point) Mul(k int) Point
    func (p Point) String() string
    func (p Point) Sub(q Point) Point
type RGBA
    func NewRGBA(r Rectangle) *RGBA
    func (p *RGBA) At(x, y int) color.Color
    func (p *RGBA) Bounds() Rectangle
    func (p *RGBA) ColorModel() color.Model
    func (p *RGBA) Opaque() bool
    func (p *RGBA) PixOffset(x, y int) int
    func (p *RGBA) RGBAAt(x, y int) color.RGBA
    func (p *RGBA) Set(x, y int, c color.Color)
    func (p *RGBA) SetRGBA(x, y int, c color.RGBA)
    func (p *RGBA) SubImage(r Rectangle) Image
type RGBA64
    func NewRGBA64(r Rectangle) *RGBA64
    func (p *RGBA64) At(x, y int) color.Color
    func (p *RGBA64) Bounds() Rectangle
    func (p *RGBA64) ColorModel() color.Model
    func (p *RGBA64) Opaque() bool
    func (p *RGBA64) PixOffset(x, y int) int
    func (p *RGBA64) RGBA64At(x, y int) color.RGBA64
    func (p *RGBA64) Set(x, y int, c color.Color)
    func (p *RGBA64) SetRGBA64(x, y int, c color.RGBA64)
    func (p *RGBA64) SubImage(r Rectangle) Image
type Rectangle
    func Rect(x0, y0, x1, y1 int) Rectangle
    func (r Rectangle) Add(p Point) Rectangle
    func (r Rectangle) At(x, y int) color.Color
    func (r Rectangle) Bounds() Rectangle
    func (r Rectangle) Canon() Rectangle
    func (r Rectangle) ColorModel() color.Model
    func (r Rectangle) Dx() int
    func (r Rectangle) Dy() int
    func (r Rectangle) Empty() bool
    func (r Rectangle) Eq(s Rectangle) bool
    func (r Rectangle) In(s Rectangle) bool
    func (r Rectangle) Inset(n int) Rectangle
    func (r Rectangle) Intersect(s Rectangle) Rectangle
    func (r Rectangle) Overlaps(s Rectangle) bool
    func (r Rectangle) Size() Point
    func (r Rectangle) String() string
    func (r Rectangle) Sub(p Point) Rectangle
    func (r Rectangle) Union(s Rectangle) Rectangle
type Uniform
    func NewUniform(c color.Color) *Uniform
    func (c *Uniform) At(x, y int) color.Color
    func (c *Uniform) Bounds() Rectangle
    func (c *Uniform) ColorModel() color.Model
    func (c *Uniform) Convert(color.Color) color.Color
    func (c *Uniform) Opaque() bool
    func (c *Uniform) RGBA() (r, g, b, a uint32)
type YCbCr
    func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr
    func (p *YCbCr) At(x, y int) color.Color
    func (p *YCbCr) Bounds() Rectangle
    func (p *YCbCr) COffset(x, y int) int
    func (p *YCbCr) ColorModel() color.Model
    func (p *YCbCr) Opaque() bool
    func (p *YCbCr) SubImage(r Rectangle) Image
    func (p *YCbCr) YCbCrAt(x, y int) color.YCbCr
    func (p *YCbCr) YOffset(x, y int) int
type YCbCrSubsampleRatio
    func (s YCbCrSubsampleRatio) String() string

Examples

Package
Package (DecodeConfig)

Package files

format.go geom.go image.go names.go ycbcr.go

Variables

var (
    // Black is an opaque black uniform image.
    Black = NewUniform(color.Black)
    // White is an opaque white uniform image.
    White = NewUniform(color.White)
    // Transparent is a fully transparent uniform image.
    Transparent = NewUniform(color.Transparent)
    // Opaque is a fully opaque uniform image.
    Opaque = NewUniform(color.Opaque)
)

ErrFormat表示解码遇到未知格式.

var ErrFormat = errors.New("image: unknown format")

func RegisterFormat

func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))

RegisterFormat注册供Decode使用的图像格式. Name是格式的名称,例如" jpeg"或" png". 魔术是标识格式编码的魔术前缀. 魔术字符串可以包含"?" 每个匹配任意一个字节的通配符. 解码是对编码图像进行解码的功能. DecodeConfig是仅解码其配置的函数.

type Alpha

Alpha是内存中的图像,其At方法返回color.Alpha值.

type Alpha struct {
    // Pix holds the image's pixels, as alpha values. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewAlpha

func NewAlpha(r Rectangle) *Alpha

NewAlpha返回具有给定边界的新Alpha图像.

func (*Alpha) AlphaAt 1.4

func (p *Alpha) AlphaAt(x, y int) color.Alpha

func (*Alpha) At

func (p *Alpha) At(x, y int) color.Color

func (*Alpha) Bounds

func (p *Alpha) Bounds() Rectangle

func (*Alpha) ColorModel

func (p *Alpha) ColorModel() color.Model

func (*Alpha) Opaque

func (p *Alpha) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Alpha) PixOffset

func (p *Alpha) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*Alpha) Set

func (p *Alpha) Set(x, y int, c color.Color)

func (*Alpha) SetAlpha

func (p *Alpha) SetAlpha(x, y int, c color.Alpha)

func (*Alpha) SubImage

func (p *Alpha) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type Alpha16

Alpha16是内存中的图像,其At方法返回color.Alpha16值.

type Alpha16 struct {
    // Pix holds the image's pixels, as alpha values in big-endian format. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewAlpha16

func NewAlpha16(r Rectangle) *Alpha16

NewAlpha16返回具有给定边界的新Alpha16图像.

func (*Alpha16) Alpha16At 1.4

func (p *Alpha16) Alpha16At(x, y int) color.Alpha16

func (*Alpha16) At

func (p *Alpha16) At(x, y int) color.Color

func (*Alpha16) Bounds

func (p *Alpha16) Bounds() Rectangle

func (*Alpha16) ColorModel

func (p *Alpha16) ColorModel() color.Model

func (*Alpha16) Opaque

func (p *Alpha16) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Alpha16) PixOffset

func (p *Alpha16) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*Alpha16) Set

func (p *Alpha16) Set(x, y int, c color.Color)

func (*Alpha16) SetAlpha16

func (p *Alpha16) SetAlpha16(x, y int, c color.Alpha16)

func (*Alpha16) SubImage

func (p *Alpha16) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type CMYK 1.5

CMYK是内存中的图像,其At方法返回color.CMYK值.

type CMYK struct {
    // Pix holds the image's pixels, in C, M, Y, K order. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewCMYK 1.5

func NewCMYK(r Rectangle) *CMYK

NewCMYK返回具有给定边界的新CMYK图像.

func (*CMYK) At 1.5

func (p *CMYK) At(x, y int) color.Color

func (*CMYK) Bounds 1.5

func (p *CMYK) Bounds() Rectangle

func (*CMYK) CMYKAt 1.5

func (p *CMYK) CMYKAt(x, y int) color.CMYK

func (*CMYK) ColorModel 1.5

func (p *CMYK) ColorModel() color.Model

func (*CMYK) Opaque 1.5

func (p *CMYK) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*CMYK) PixOffset 1.5

func (p *CMYK) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*CMYK) Set 1.5

func (p *CMYK) Set(x, y int, c color.Color)

func (*CMYK) SetCMYK 1.5

func (p *CMYK) SetCMYK(x, y int, c color.CMYK)

func (*CMYK) SubImage 1.5

func (p *CMYK) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type Config

Config保存图像的颜色模型和尺寸.

type Config struct {
    ColorModel    color.Model
    Width, Height int
}

func DecodeConfig

func DecodeConfig(r io.Reader) (Config, string, error)

DecodeConfig解码已以注册格式编码的图像的颜色模型和尺寸. 返回的字符串是格式注册期间使用的格式名称. 格式注册通常由特定于编解码器的程序包中的init函数完成.

type Gray

灰度是内存中的图像,其At方法返回color.Gray值.

type Gray struct {
    // Pix holds the image's pixels, as gray values. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewGray

func NewGray(r Rectangle) *Gray

NewGray返回具有给定范围的新灰度图像.

func (*Gray) At

func (p *Gray) At(x, y int) color.Color

func (*Gray) Bounds

func (p *Gray) Bounds() Rectangle

func (*Gray) ColorModel

func (p *Gray) ColorModel() color.Model

func (*Gray) GrayAt 1.4

func (p *Gray) GrayAt(x, y int) color.Gray

func (*Gray) Opaque

func (p *Gray) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Gray) PixOffset

func (p *Gray) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*Gray) Set

func (p *Gray) Set(x, y int, c color.Color)

func (*Gray) SetGray

func (p *Gray) SetGray(x, y int, c color.Gray)

func (*Gray) SubImage

func (p *Gray) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Gray16

Gray16是内存中的图像,其At方法返回color.Gray16值.

type Gray16 struct {
    // Pix holds the image's pixels, as gray values in big-endian format. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewGray16

func NewGray16(r Rectangle) *Gray16

NewGray16返回具有给定边界的新Gray16图像.

func (*Gray16) At

func (p *Gray16) At(x, y int) color.Color

func (*Gray16) Bounds

func (p *Gray16) Bounds() Rectangle

func (*Gray16) ColorModel

func (p *Gray16) ColorModel() color.Model

func (*Gray16) Gray16At 1.4

func (p *Gray16) Gray16At(x, y int) color.Gray16

func (*Gray16) Opaque

func (p *Gray16) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Gray16) PixOffset

func (p *Gray16) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*Gray16) Set

func (p *Gray16) Set(x, y int, c color.Color)

func (*Gray16) SetGray16

func (p *Gray16) SetGray16(x, y int, c color.Gray16)

func (*Gray16) SubImage

func (p *Gray16) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type Image

图像是颜色的有限矩形网格.颜色值取自颜色模型.

type Image interface {
    // ColorModel returns the Image's color model.
    ColorModel() color.Model
    // Bounds returns the domain for which At can return non-zero color.
    // The bounds do not necessarily contain the point (0, 0).
    Bounds() Rectangle
    // At returns the color of the pixel at (x, y).
    // At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
    // At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
    At(x, y int) color.Color
}

func Decode

func Decode(r io.Reader) (Image, string, error)

解码解码以注册格式编码的图像. 返回的字符串是格式注册期间使用的格式名称. 格式注册通常由特定于编解码器的程序包中的init函数完成.

type NRGBA

NRGBA是内存中的图像,其At方法返回color.NRGBA值.

type NRGBA struct {
    // Pix holds the image's pixels, in R, G, B, A order. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewNRGBA

func NewNRGBA(r Rectangle) *NRGBA

NewNRGBA返回具有给定边界的新NRGBA图像.

func (*NRGBA) At

func (p *NRGBA) At(x, y int) color.Color

func (*NRGBA) Bounds

func (p *NRGBA) Bounds() Rectangle

func (*NRGBA) ColorModel

func (p *NRGBA) ColorModel() color.Model

func (*NRGBA) NRGBAAt 1.4

func (p *NRGBA) NRGBAAt(x, y int) color.NRGBA

func (*NRGBA) Opaque

func (p *NRGBA) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*NRGBA) PixOffset

func (p *NRGBA) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*NRGBA) Set

func (p *NRGBA) Set(x, y int, c color.Color)

func (*NRGBA) SetNRGBA

func (p *NRGBA) SetNRGBA(x, y int, c color.NRGBA)

func (*NRGBA) SubImage

func (p *NRGBA) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type NRGBA64

NRGBA64是内存中的图像,其At方法返回color.NRGBA64值.

type NRGBA64 struct {
    // Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewNRGBA64

func NewNRGBA64(r Rectangle) *NRGBA64

NewNRGBA64返回具有给定边界的新NRGBA64图像.

func (*NRGBA64) At

func (p *NRGBA64) At(x, y int) color.Color

func (*NRGBA64) Bounds

func (p *NRGBA64) Bounds() Rectangle

func (*NRGBA64) ColorModel

func (p *NRGBA64) ColorModel() color.Model

func (*NRGBA64) NRGBA64At 1.4

func (p *NRGBA64) NRGBA64At(x, y int) color.NRGBA64

func (*NRGBA64) Opaque

func (p *NRGBA64) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*NRGBA64) PixOffset

func (p *NRGBA64) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*NRGBA64) Set

func (p *NRGBA64) Set(x, y int, c color.Color)

func (*NRGBA64) SetNRGBA64

func (p *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)

func (*NRGBA64) SubImage

func (p *NRGBA64) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type NYCbCrA 1.6

NYCbCrA is an in-memory image of non-alpha-premultiplied Y'CbCr-with-alpha colors. A and AStride are analogous to the Y and YStride fields of the embedded YCbCr.

type NYCbCrA struct {
    YCbCr
    A       []uint8
    AStride int
}

func NewNYCbCrA 1.6

func NewNYCbCrA(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *NYCbCrA

NewNYCbCrA返回具有给定范围和子采样率的新NYCbCrA图像.

func (*NYCbCrA) AOffset 1.6

func (p *NYCbCrA) AOffset(x, y int) int

AOffset返回A的第一个元素的索引,该元素对应于(x,y)处的像素.

func (*NYCbCrA) At 1.6

func (p *NYCbCrA) At(x, y int) color.Color

func (*NYCbCrA) ColorModel 1.6

func (p *NYCbCrA) ColorModel() color.Model

func (*NYCbCrA) NYCbCrAAt 1.6

func (p *NYCbCrA) NYCbCrAAt(x, y int) color.NYCbCrA

func (*NYCbCrA) Opaque 1.6

func (p *NYCbCrA) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*NYCbCrA) SubImage 1.6

func (p *NYCbCrA) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type Paletted

调色板是给定调色板中uint8索引的内存图像.

type Paletted struct {
    // Pix holds the image's pixels, as palette indices. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
    // Palette is the image's palette.
    Palette color.Palette
}

func NewPaletted

func NewPaletted(r Rectangle, p color.Palette) *Paletted

NewPaletted返回具有给定宽度,高度和调色板的新调色板图像.

func (*Paletted) At

func (p *Paletted) At(x, y int) color.Color

func (*Paletted) Bounds

func (p *Paletted) Bounds() Rectangle

func (*Paletted) ColorIndexAt

func (p *Paletted) ColorIndexAt(x, y int) uint8

func (*Paletted) ColorModel

func (p *Paletted) ColorModel() color.Model

func (*Paletted) Opaque

func (p *Paletted) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Paletted) PixOffset

func (p *Paletted) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*Paletted) Set

func (p *Paletted) Set(x, y int, c color.Color)

func (*Paletted) SetColorIndex

func (p *Paletted) SetColorIndex(x, y int, index uint8)

func (*Paletted) SubImage

func (p *Paletted) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type PalettedImage

PalettedImage是图像,其颜色可能来自有限的调色板. 如果m是一个PalettedImage,并且m.ColorModel()返回一个color.Palette p,则m.At(x,y)应等效于p [m.ColorIndexAt(x,y)]. 如果m的颜色模型不是color.Palette,则ColorIndexAt的行为未定义.

type PalettedImage interface {
    // ColorIndexAt returns the palette index of the pixel at (x, y).
    ColorIndexAt(x, y int) uint8
    Image
}

type Point

点是X,Y坐标对. 轴向右和向下增加.

type Point struct {
    X, Y int
}

ZP是零点.

不推荐使用:改为使用文字image.Point {}.

var ZP Point

func Pt

func Pt(X, Y int) Point

Pt是Point {X,Y}的简写.

func (Point) Add

func (p Point) Add(q Point) Point

加法返回向量p + q.

func (Point) Div

func (p Point) Div(k int) Point

Div返回向量p / k.

func (Point) Eq

func (p Point) Eq(q Point) bool

Eq报告p和q是否相等.

func (Point) In

func (p Point) In(r Rectangle) bool

在报告中p是否在r中.

func (Point) Mod

func (p Point) Mod(r Rectangle) Point

Mod返回r中的点q,以使pX-qX是r的宽度的倍数,而pY-qY是r的高度的倍数.

func (Point) Mul

func (p Point) Mul(k int) Point

Mul返回向量p * k.

func (Point) String

func (p Point) String() string

String返回p的字符串表示形式,例如"(3,4)".

func (Point) Sub

func (p Point) Sub(q Point) Point

Sub返回向量pq.

type RGBA

RGBA是内存中的图像,其At方法返回color.RGBA值.

type RGBA struct {
    // Pix holds the image's pixels, in R, G, B, A order. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewRGBA

func NewRGBA(r Rectangle) *RGBA

NewRGBA返回具有给定边界的新RGBA图像.

func (*RGBA) At

func (p *RGBA) At(x, y int) color.Color

func (*RGBA) Bounds

func (p *RGBA) Bounds() Rectangle

func (*RGBA) ColorModel

func (p *RGBA) ColorModel() color.Model

func (*RGBA) Opaque

func (p *RGBA) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*RGBA) PixOffset

func (p *RGBA) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*RGBA) RGBAAt 1.4

func (p *RGBA) RGBAAt(x, y int) color.RGBA

func (*RGBA) Set

func (p *RGBA) Set(x, y int, c color.Color)

func (*RGBA) SetRGBA

func (p *RGBA) SetRGBA(x, y int, c color.RGBA)

func (*RGBA) SubImage

func (p *RGBA) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type RGBA64

RGBA64是内存中的图像,其At方法返回color.RGBA64值.

type RGBA64 struct {
    // Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect Rectangle
}

func NewRGBA64

func NewRGBA64(r Rectangle) *RGBA64

NewRGBA64返回具有给定边界的新RGBA64图像.

func (*RGBA64) At

func (p *RGBA64) At(x, y int) color.Color

func (*RGBA64) Bounds

func (p *RGBA64) Bounds() Rectangle

func (*RGBA64) ColorModel

func (p *RGBA64) ColorModel() color.Model

func (*RGBA64) Opaque

func (p *RGBA64) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*RGBA64) PixOffset

func (p *RGBA64) PixOffset(x, y int) int

PixOffset返回与(x,y)处像素相对应的Pix第一个元素的索引.

func (*RGBA64) RGBA64At 1.4

func (p *RGBA64) RGBA64At(x, y int) color.RGBA64

func (*RGBA64) Set

func (p *RGBA64) Set(x, y int, c color.Color)

func (*RGBA64) SetRGBA64

func (p *RGBA64) SetRGBA64(x, y int, c color.RGBA64)

func (*RGBA64) SubImage

func (p *RGBA64) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

type Rectangle

矩形包含最小X <= X <最大X,最小Y <= Y <最大Y的点. 如果Min.X <= Max.X,则格式正确,对于Y也是如此.点始终格式正确. 矩形的方法始终为格式正确的输入返回格式良好的输出.

矩形也是图像,其边界是矩形本身. 在返回color.Opaque为矩形和color中的点,否则为透明.

type Rectangle struct {
    Min, Max Point
}

ZR是零矩形.

不推荐使用:改用文字图像.Rectangle{}.

var ZR Rectangle

func Rect

func Rect(x0, y0, x1, y1 int) Rectangle

Rect是Rectangle {Pt(x0,y0),Pt(x1,y1)}的简写. 返回的矩形在必要时会交换最小和最大坐标,以便格式正确.

func (Rectangle) Add

func (r Rectangle) Add(p Point) Rectangle

Add返回由p转换的矩形r.

func (Rectangle) At 1.5

func (r Rectangle) At(x, y int) color.Color

在实现Image接口.

func (Rectangle) Bounds 1.5

func (r Rectangle) Bounds() Rectangle

Bounds实现了Image接口.

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

佳能返回r的规范版本. 返回的矩形在必要时会交换最小和最大坐标,以便格式正确.

func (Rectangle) ColorModel 1.5

func (r Rectangle) ColorModel() color.Model

ColorModel实现了Image接口.

func (Rectangle) Dx

func (r Rectangle) Dx() int

Dx返回r的宽度.

func (Rectangle) Dy

func (r Rectangle) Dy() int

Dy返回r的高度.

func (Rectangle) Empty

func (r Rectangle) Empty() bool

空报告矩形是否不包含点.

func (Rectangle) Eq

func (r Rectangle) Eq(s Rectangle) bool

公式报告r和s是否包含相同的点集. 所有空矩形均视为相等.

func (Rectangle) In

func (r Rectangle) In(s Rectangle) bool

在报告中,r中的每个点是否都在s中.

func (Rectangle) Inset

func (r Rectangle) Inset(n int) Rectangle

Inset返回以n为单位的矩形r inset,该值可以为负. 如果r的任一尺寸小于2 * n,则将返回r中心附近的空矩形.

func (Rectangle) Intersect

func (r Rectangle) Intersect(s Rectangle) Rectangle

相交返回r和s包含的最大矩形. 如果两个矩形不重叠,则将返回零矩形.

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(s Rectangle) bool

重叠报告r和s是否具有非空交集.

func (Rectangle) Size

func (r Rectangle) Size() Point

大小返回r的宽度和高度.

func (Rectangle) String

func (r Rectangle) String() string

String返回r的字符串表示形式,例如"(3,4)-(6,5)".

func (Rectangle) Sub

func (r Rectangle) Sub(p Point) Rectangle

Sub返回由-p转换的矩形r.

func (Rectangle) Union

func (r Rectangle) Union(s Rectangle) Rectangle

Union返回包含r和s的最小矩形.

type Uniform

均匀是无限大小的均匀颜色图像. 它实现了color.Color,color.Model和Image接口.

type Uniform struct {
    C color.Color
}

func NewUniform

func NewUniform(c color.Color) *Uniform

func (*Uniform) At

func (c *Uniform) At(x, y int) color.Color

func (*Uniform) Bounds

func (c *Uniform) Bounds() Rectangle

func (*Uniform) ColorModel

func (c *Uniform) ColorModel() color.Model

func (*Uniform) Convert

func (c *Uniform) Convert(color.Color) color.Color

func (*Uniform) Opaque

func (c *Uniform) Opaque() bool

不透明图像会扫描整个图像,并报告其是否完全不透明.

func (*Uniform) RGBA

func (c *Uniform) RGBA() (r, g, b, a uint32)

type YCbCr

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.
For 4:1:1, CStride == YStride/4 && len(Cb) == len(Cr) == len(Y)/4.
For 4:1:0, CStride == YStride/4 && len(Cb) == len(Cr) == len(Y)/8.
type YCbCr struct {
    Y, Cb, Cr      []uint8
    YStride        int
    CStride        int
    SubsampleRatio YCbCrSubsampleRatio
    Rect           Rectangle
}

func NewYCbCr

func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr

NewYCbCr返回具有给定范围和子采样率的新YCbCr图像.

func (*YCbCr) At

func (p *YCbCr) At(x, y int) color.Color

func (*YCbCr) Bounds

func (p *YCbCr) Bounds() Rectangle

func (*YCbCr) COffset

func (p *YCbCr) COffset(x, y int) int

COffset返回与(x,y)处的像素相对应的Cb或Cr第一个元素的索引.

func (*YCbCr) ColorModel

func (p *YCbCr) ColorModel() color.Model

func (*YCbCr) Opaque

func (p *YCbCr) Opaque() bool

func (*YCbCr) SubImage

func (p *YCbCr) SubImage(r Rectangle) Image

SubImage返回一个图像,该图像表示通过r可见的图像p的一部分. 返回的值与原始图像共享像素.

func (*YCbCr) YCbCrAt 1.4

func (p *YCbCr) YCbCrAt(x, y int) color.YCbCr

func (*YCbCr) YOffset

func (p *YCbCr) YOffset(x, y int) int

YOffset返回与(x,y)处的像素相对应的Y的第一个元素的索引.

type YCbCrSubsampleRatio

YCbCrSubsampleRatio是YCbCr图像中使用的色度子采样率.

type YCbCrSubsampleRatio int
const (
    YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iota
    YCbCrSubsampleRatio422
    YCbCrSubsampleRatio420
    YCbCrSubsampleRatio440
    YCbCrSubsampleRatio411
    YCbCrSubsampleRatio410
)

func (YCbCrSubsampleRatio) String

func (s YCbCrSubsampleRatio) String() string

Subdirectories

Name Synopsis
..
color 包颜色实现一个基本的颜色库.
palette 包装调色板提供标准的调色板.
draw 打包绘图提供图像合成功能.
gif 包gif实现了GIF图像解码器和编码器.
jpeg 软件包jpeg实现了JPEG图像解码器和编码器.
png png包实现了PNG图像解码器和编码器.

by  ICOPY.SITE