Package png

import "image/png"

概览 ▾

png 包实现了PNG图像的编码和解码.


func Decode

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

Decode reads a PNG image from r and returns it as an image.Image. The type of Image returned depends on the PNG contents.

func DecodeConfig

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


func Encode

func Encode(w io.Writer, m image.Image) error

Encode将图片m以PNG的格式写到w中。任何图片都可以被编码,但是哪些不是 image.NRGBA 的图片编码可能是有损的。

type CompressionLevel

type CompressionLevel int
const (
    DefaultCompression CompressionLevel = 0
    NoCompression      CompressionLevel = -1
    BestSpeed          CompressionLevel = -2
    BestCompression    CompressionLevel = -3

type Encoder

type Encoder struct {
    CompressionLevel CompressionLevel

Encoder configures encoding PNG images.

func (*Encoder) Encode

func (enc *Encoder) Encode(w io.Writer, m image.Image) error

Encode 将图像 m 以 PNG 格式写入 w。

type FormatError

type FormatError string


func (FormatError) Error

func (e FormatError) Error() string

type UnsupportedError

type UnsupportedError string


func (UnsupportedError) Error

func (e UnsupportedError) Error() string