feat: 添加GIF支持,更新SaveToGIF方法以使用WebSafe调色板,新增nailong.gif文件,更新main.go以处理GIF精灵。
This commit is contained in:
@@ -2,6 +2,7 @@ package sprite
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color/palette"
|
||||
"image/draw"
|
||||
"image/gif"
|
||||
"image/png"
|
||||
@@ -877,9 +878,9 @@ func (b *NamedSpriteBoard) SaveToGIF(filename string) error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// 将RGBA图像转换为Paletted图像
|
||||
// 将RGBA图像转换为Paletted图像,使用WebSafe调色板
|
||||
bounds := img.Bounds()
|
||||
palettedImg := image.NewPaletted(bounds, nil)
|
||||
palettedImg := image.NewPaletted(bounds, palette.WebSafe)
|
||||
draw.Draw(palettedImg, bounds, img, bounds.Min, draw.Src)
|
||||
|
||||
// 将图像编码为GIF并写入文件
|
||||
@@ -899,7 +900,7 @@ func (b *NamedSpriteBoard) SaveToGIF(filename string) error {
|
||||
// 转换所有帧为Paletted图像
|
||||
for i, frame := range frames {
|
||||
bounds := frame.Bounds()
|
||||
palettedFrames[i] = image.NewPaletted(bounds, nil)
|
||||
palettedFrames[i] = image.NewPaletted(bounds, palette.WebSafe)
|
||||
draw.Draw(palettedFrames[i], bounds, frame, bounds.Min, draw.Src)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user