#ani #riff #generate #mouse #cursor #animated #windows

riff-ani

为 Windows 生成动画鼠标光标文件 (.ani)

1 个不稳定版本

0.1.0 2020年11月18日

#6 in #animated

每月下载 37 次
用于 wcursorgen

MPL-2.0 许可证

8KB
60

riff-ani

为 Windows 生成动画鼠标光标文件 (.ani)。

示例

use riff_ani::ico::{IconDir, IconDirEntry, IconImage, ResourceType};
use riff_ani::{Ani, AniHeader};

fn main() {
    let frames = vec![
        "./images/1.png",
        "./images/2.png",
        "./images/3.png",
        "./images/4.png",
    ];

    let out = File::create("./output.ani")
        .unwrap_or_else(|_| panic!("cannot create file {}", dest.to_string_lossy()));

    let ani = Ani {
        header: AniHeader {
            num_frames: frames.len() as u32,
            num_steps: frames.len() as u32,
            width: 48,
            height: 48,
            frame_rate: 2,
        },
        frames: frames.iter().map(create_cur).collect(),
    };

    ani.encode(&out)
        .unwrap_or_else(|_| panic!("cannot write file {}", dest.to_string_lossy()));
}

fn create_cur(path: &str) -> IconDir {
    let mut icon_dir = IconDir::new(ResourceType::Cursor);

    let file = std::fs::File::open(path)
        .unwrap_or_else(|_| panic!("cannot open png {}", path));

    let mut image = IconImage::read_png(file)
        .unwrap_or_else(|_| panic!("cannot read png {}", path));

    image.set_cursor_hotspot(Some((8, 8)));

    let entry = IconDirEntry::encode_as_png(&image)
        .unwrap_or_else(|_| panic!("cannot encode png {}", path));

    icon_dir.add_entry(entry);
    icon_dir
}

也可以查看icocrate的文档。

依赖项

~1.1–1.7MB
~35K SLoC