# package draw
`import "image/draw"`
draw包提供了图像合成函数。参见:[http://golang.org/doc/articles/image_draw.html](http://golang.org/doc/articles/image_draw.html)
## Index
* [type Quantizer](#Quantizer)
* [type Image](#Image)
* [type Drawer](#Drawer)
* [type Op](#Op)
* [func (op Op) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)](#Op.Draw)
* [func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op)](#Draw)
* [func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op)](#DrawMask)
## type [Quantizer](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L26 "View Source")
```
type Quantizer interface {
// Quantize方法向p中最多增加cap(p)-len(p)个色彩并返回修正后的调色板
// 返回值更适合(可以更少失真的)将m转换为一个调色板类型的图像
Quantize(p color.Palette, m image.Image) color.Palette
}
```
Quantizer接口为一个图像生成调色板。
## type [Image](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L20 "View Source")
```
type Image interface {
image.Image
Set(x, y int, c color.Color)
}
```
Image接口比image.Image接口多了Set方法,该方法用于修改单个像素的色彩。
## type [Drawer](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L49 "View Source")
```
type Drawer interface {
// 对齐图像dst的r.Min和src的sp点,然后将src绘制到dst上的结果来替换矩形范围内的图像
Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)
}
```
Drawer包含Draw方法。
```
var FloydSteinberg Drawer = floydSteinberg{}
```
FloydSteinberg是采用Src操作并实现了Floyd-Steinberg误差扩散算法的Drawer。
## type [Op](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L33 "View Source")
```
type Op int
```
Op是Porter-Duff合成的操作符。
```
const (
// 源图像透过遮罩后,覆盖在目标图像上(类似图层)
Over Op = iota
// 源图像透过遮罩后,替换掉目标图像
Src
)
```
### func (Op) [Draw](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L44 "View Source")
```
func (op Op) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)
```
Draw方法通过使用Op参数调用包的Draw函数实现了Drawer接口。
## func [Draw](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L97 "View Source")
```
func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op)
```
Draw函数使用nil的mask参数调用DrawMask函数。
## func [DrawMask](https://github.com/golang/go/blob/master/src/image/draw/draw.go#L103 "View Source")
```
func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op)
```
对齐目标图像dst的矩形r左上角、源图像src的sp点、遮罩mask的mp点,根据op修改dst的r矩形区域内的内容,mask如果为nil则视为完全透明。
- 库
- 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