Class GifEncoder
java.lang.Object
cloud.opencode.base.captcha.codec.GifEncoder
GIF Encoder - Encodes images to animated GIF format
GIF 编码器 - 将图像编码为动画 GIF 格式
This class provides GIF encoding functionality for creating animated GIF CAPTCHAs.
此类提供 GIF 编码功能,用于创建动画 GIF 验证码。
Usage Examples | 使用示例:
GifEncoder encoder = new GifEncoder();
encoder.start(outputStream);
encoder.setRepeat(0); // loop forever
encoder.setDelay(100); // 100ms between frames
encoder.addFrame(image1);
encoder.addFrame(image2);
encoder.finish();
Features | 主要功能:
- Animated GIF creation - 创建动画GIF
- Frame delay and repeat control - 帧延迟和重复控制
- Color quantization support - 颜色量化支持
Security | 安全性:
- Thread-safe: No (single-threaded use) - 线程安全: 否(单线程使用)
- Null-safe: No (images must not be null) - 空值安全: 否(图像不能为null)
Performance | 性能特性:
- Time complexity: O(W×H) per frame (W=width, H=height) - 时间复杂度: 每帧 O(W×H)
- Space complexity: O(W×H) for indexed pixel buffer - 空间复杂度: O(W×H) 索引像素缓冲区
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a frame to the GIF.booleanfinish()Finishes the GIF encoding.voidsetDelay(int ms) Sets the delay time between frames.voidsetDispose(int code) Sets the disposal method.voidsetQuality(int quality) Sets the color quantization quality.voidsetRepeat(int iter) Sets the repeat count.booleanstart(OutputStream os) Starts GIF encoding to the output stream.
-
Constructor Details
-
GifEncoder
public GifEncoder()
-
-
Method Details
-
setDelay
public void setDelay(int ms) Sets the delay time between frames. 设置帧之间的延迟时间。- Parameters:
ms- the delay in milliseconds | 延迟(毫秒)
-
setDispose
public void setDispose(int code) Sets the disposal method. 设置处理方法。- Parameters:
code- the disposal code | 处理代码
-
setRepeat
public void setRepeat(int iter) Sets the repeat count. 设置重复次数。- Parameters:
iter- 0 for infinite, -1 for no repeat, otherwise repeat count 0 表示无限,-1 表示不重复,否则为重复次数
-
setQuality
public void setQuality(int quality) Sets the color quantization quality. 设置颜色量化质量。- Parameters:
quality- 1-30, lower is better quality but slower (default 10) 1-30,越低质量越好但越慢(默认 10)
-
start
Starts GIF encoding to the output stream. 开始 GIF 编码到输出流。- Parameters:
os- the output stream | 输出流- Returns:
- true if started successfully | 如果成功启动返回 true
-
addFrame
Adds a frame to the GIF. 添加帧到 GIF。- Parameters:
im- the frame image | 帧图像- Returns:
- true if added successfully | 如果成功添加返回 true
-
finish
public boolean finish()Finishes the GIF encoding. 完成 GIF 编码。- Returns:
- true if finished successfully | 如果成功完成返回 true
-