我发现一个示例在 Windows 中无法正常工作。该程序演示了 Go 标准图像包的基本用法,我们将使用它来创建位图图像序列,然后将该序列编码为 GIF 动画。
package main
import (
"image"
"image/color"
"image/gif"
"io"
"math"
"math/rand"
"os"
)
import (
"log"
"net/http"
"time"
)
//!+main
var palette = []color.Color{color.White, color.Black}
const (
whiteIndex = 0 // first color in palette
blackIndex = 1 // next color in palette
)
func main() {
//!-main
// The sequence of images is deterministic unless we seed
// the pseudo-random number generator using the current time.
// Thanks to Randall McPherson for pointing …Run Code Online (Sandbox Code Playgroud)