GIF 编码器和解码器
GIF en- and decoder written in Rust (API Documentation).
This library provides all functions necessary to de- and encode GIF files.
The high level interface consists of the two types
Encoder and Decoder.
// Open the file
use std::fs::File;
let input = File::open("tests/samples/sample_1.gif").unwrap();
// Configure the decoder such that it will expand the image to RGBA.
let mut options = gif::DecodeOptions::new();
options.set_color_output(gif::ColorOutput::RGBA);
// Read the file header
let mut decoder = options.read_info(input).unwrap();
while let Some(frame) = decoder.read_next_frame().unwrap() {
// Process every frame
}The encoder can be used to save simple computer generated images:
…Frame::from_* can be used to convert a true color image to a paletted
image with a maximum of 256 colors:
use std::fs::File;
// Get pixel data from some source
let mut pixels: Vec = vec![0; 30_000];
// Create frame from data
let frame = gif::Frame::from_rgb(100, 100, &mut *pixels);
// Create encoder
let mut image = File::create("target/indexed_color.gif").unwrap();
let mut encoder = gif::Encoder::new(&mut image, frame.width, frame.height, &[]).unwrap();
// Write frame to file
encoder.write_frame(&frame).unwrap();暂无开放 Issues,或尚未同步最近议题。