如何在 Go 中创建透明 gif?
How do I create a transparent gif in Go?
当我用 Go 编码 gif 时,背景全黑了。如何使背景透明?
这是我的 http 处理程序中的一些代码。 (w 是 responseWriter)
m := image.NewRGBA(image.Rect(0, 0, pixelWidth, pixelHeight))
gif.Encode(w, m, &gif.Options{NumColors: 16})
我阅读了 image/gif 的来源,发现您的调色板上必须有透明色。
var palette color.Palette = color.Palette{
image.Transparent,
image.Black,
image.White,
color.RGBA{0, 255, 0, 255},
color.RGBA{0, 100, 0, 255},
}
m := image.NewPaletted(image.Rect(0, 0, pixelWidth, pixelHeight), palette)
gif.Encode(w, m, &gif.Options{})
当我用 Go 编码 gif 时,背景全黑了。如何使背景透明?
这是我的 http 处理程序中的一些代码。 (w 是 responseWriter)
m := image.NewRGBA(image.Rect(0, 0, pixelWidth, pixelHeight))
gif.Encode(w, m, &gif.Options{NumColors: 16})
我阅读了 image/gif 的来源,发现您的调色板上必须有透明色。
var palette color.Palette = color.Palette{
image.Transparent,
image.Black,
image.White,
color.RGBA{0, 255, 0, 255},
color.RGBA{0, 100, 0, 255},
}
m := image.NewPaletted(image.Rect(0, 0, pixelWidth, pixelHeight), palette)
gif.Encode(w, m, &gif.Options{})