feat: add gif ascii art generate

This commit is contained in:
2024-09-26 17:38:28 +08:00
parent a3058780be
commit e832b1cb3b
2 files changed
+35 -10

No files matched your search

@@ -13,12 +13,14 @@ import java.awt.image.BufferedImage
import java.io.ByteArrayOutputStream
fun GifDecoder.makeGif(frames: List<BufferedImage>): ByteArray {
val byteArrayOutputStream = ByteArrayOutputStream()
val estimatedSize = frames.size * 50 * 1024
val byteArrayOutputStream = ByteArrayOutputStream(estimatedSize)
val encoder = AnimatedGifEncoder()
encoder.start(byteArrayOutputStream)
encoder.setRepeat(0)
for (i in frames.indices) {
encoder.setDelay(this.getDelay(this.frameCount - i - 1))
val delays = frames.indices.map { this.getDelay(this.frameCount - it - 1) }
frames.indices.forEach { i ->
encoder.setDelay(delays[i])
encoder.addFrame(frames[i])
}
encoder.finish()