4 个版本

0.0.4 2020年11月19日
0.0.3 2020年10月17日
0.0.2 2020年9月30日
0.0.1 2020年8月2日

#608 in 图像

MIT 许可证

10MB
4.5K SLoC

Nanachi - 纯 Rust 2D 图形库

Build Status Crates.io Documentation

注意:Nanachi 仍然存在错误,API 将会更改!

nanachi

cargo run --release --example nanachi 生成

特性

  • 路径填充和描边
  • 颜色:线性渐变、径向渐变和图案
  • 24 种合成类型
  • 抗锯齿(可以禁用)
  • 路径转换:平移、缩放和旋转

示例

基本用法示例如下

use image::RgbaImage;
use nanachi::{
    compositor,
    context::{Context, FillStyle},
    fill_color, fill_rule,
    path_builder::PathBuilder,
    pixel::Rgba,
};

let (width, height) = (512, 512);

// Make a Context
let mut context = Context::from_pixel(width, height, Rgba([1.0, 1.0, 1.0, 1.0])).high_quality();

// Make a Path
let mut builder = PathBuilder::new();
builder.move_to(100.0, 100.0);
builder.line_to(200.0, 100.0);
builder.line_to(200.0, 200.0);
builder.line_to(100.0, 200.0);
builder.close();
let path = builder.end();

// Make a FillStyle for filling
let fill_style = FillStyle::new(
    fill_color::Solid::new(Rgba([1.0, 0.0, 0.0, 0.7])),
    compositor::SrcOver,
    fill_rule::NonZero,
);

// Fill the path
context.fill(&path, &fill_style);

// Make a FillStyle for stroking
let fill_style = FillStyle::new(
    fill_color::Solid::new(Rgba([0.0, 0.0, 1.0, 1.0])),
    compositor::SrcOver,
    fill_rule::NonZero,
);

// Stroke the path
context.stroke(&path, &fill_style, 8.0);

// Save the image
let img: RgbaImage = (&context.image).into();
img.save("./basic.png").unwrap();

作者

版权所有 (c) 2020 carrotflakes (carrotflakes@gmail.com)

许可证

许可协议:MIT 许可证。

依赖项

~1–3.5MB
~28K SLoC