💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# package png `import "image/png"` png包实现了PNG图像的编解码。PNG格式参见:[http://www.w3.org/TR/PNG/](http://www.w3.org/TR/PNG/) ## Index * [type FormatError](#FormatError) * [func (e FormatError) Error() string](#FormatError.Error) * [type UnsupportedError](#UnsupportedError) * [func (e UnsupportedError) Error() string](#UnsupportedError.Error) * [func Decode(r io.Reader) (image.Image, error)](#Decode) * [func DecodeConfig(r io.Reader) (image.Config, error)](#DecodeConfig) * [func Encode(w io.Writer, m image.Image) error](#Encode) ## type [FormatError](https://github.com/golang/go/blob/master/src/image/png/reader.go#L90 "View Source") ``` type FormatError string ``` 当输入流不是合法的png格式图像时,就会返回FormatError类型的错误。 ### func (FormatError) [Error](https://github.com/golang/go/blob/master/src/image/png/reader.go#L92 "View Source") ``` func (e FormatError) Error() string ``` ## type [UnsupportedError](https://github.com/golang/go/blob/master/src/image/png/reader.go#L97 "View Source") ``` type UnsupportedError string ``` 当输入流使用了合法但尚不支持的png特性的时候,就会返回UnsupportedError类型的错误。 ### func (UnsupportedError) [Error](https://github.com/golang/go/blob/master/src/image/png/reader.go#L99 "View Source") ``` func (e UnsupportedError) Error() string ``` ## func [Decode](https://github.com/golang/go/blob/master/src/image/png/reader.go#L619 "View Source") ``` func Decode(r io.Reader) (image.Image, error) ``` 从r读取一幅png格式的图像并解码返回该图像。图像的具体类型要看png文件的内容而定。 ## func [DecodeConfig](https://github.com/golang/go/blob/master/src/image/png/reader.go#L643 "View Source") ``` func DecodeConfig(r io.Reader) (image.Config, error) ``` 返回PNG图像的色彩模型和尺寸;函数不会解码整个图像。 ## func [Encode](https://github.com/golang/go/blob/master/src/image/png/writer.go#L433 "View Source") ``` func Encode(w io.Writer, m image.Image) error ``` 将图像m以PNG格式写入w。任意图像类型都可以被编码,但image.NRGBA以外格式的图像可能会在编码时丢失一些图像信息。