# package jpeg
`import "image/jpeg"`
jpeg包实现了jpeg格式图像的编解码。JPEG格式参见[http://www.w3.org/Graphics/JPEG/itu-t81.pdf](http://www.w3.org/Graphics/JPEG/itu-t81.pdf)
## Index
* [Constants](#pkg-constants)
* [type Reader](#Reader)
* [type FormatError](#FormatError)
* [func (e FormatError) Error() string](#FormatError.Error)
* [type UnsupportedError](#UnsupportedError)
* [func (e UnsupportedError) Error() string](#UnsupportedError.Error)
* [type Options](#Options)
* [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, o \*Options) error](#Encode)
## Constants
```
const DefaultQuality = 75
```
DefaultQuality是默认的编码质量参数。
## type [Reader](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L88 "View Source")
```
type Reader interface {
io.Reader
ReadByte() (c byte, err error)
}
```
如果提供的io.Reader接口没有ReadByte方法,Decode函数会为该接口附加一个缓冲。
## type [FormatError](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L21 "View Source")
```
type FormatError string
```
当输入流不是合法的jpeg格式图像时,就会返回FormatError类型的错误。
### func (FormatError) [Error](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L23 "View Source")
```
func (e FormatError) Error() string
```
## type [UnsupportedError](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L26 "View Source")
```
type UnsupportedError string
```
当输入流使用了合法但尚不支持的jpeg特性的时候,就会返回UnsupportedError类型的错误。
### func (UnsupportedError) [Error](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L28 "View Source")
```
func (e UnsupportedError) Error() string
```
## type [Options](https://github.com/golang/go/blob/master/src/image/jpeg/writer.go#L488 "View Source")
```
type Options struct {
Quality int
}
```
Options是编码质量参数。取值范围[1,100],越大图像编码质量越高。
## func [Decode](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L346 "View Source")
```
func Decode(r io.Reader) (image.Image, error)
```
从r读取一幅jpeg格式的图像并解码返回该图像。
## func [DecodeConfig](https://github.com/golang/go/blob/master/src/image/jpeg/reader.go#L353 "View Source")
```
func DecodeConfig(r io.Reader) (image.Config, error)
```
返回JPEG图像的色彩模型和尺寸;函数不会解码整个图像。
## func [Encode](https://github.com/golang/go/blob/master/src/image/jpeg/writer.go#L494 "View Source")
```
func Encode(w io.Writer, m image.Image, o *Options) error
```
Encode函数将采用JPEG 4:2:0基线格式和指定的编码质量将图像写入w。如果o为nil将使用DefaultQuality。
- 库
- 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