Files
QRGen/examples/high_ecc.rs
T
Serendipity 38be82973e feat: Logo 嵌入 — QR 码中央叠加自定义图片
- PNG 渲染:RgbaImage 上使用 imageops::overlay 叠加 logo
- SVG 渲染:base64 编码 logo 嵌入 <image> 标签
- QrCode::to_png_bytes / to_svg 新增 Option<logo_bytes> 参数
- Logo 默认占 QR 区域 25%,建议配合 H 级纠错使用
2026-06-19 21:12:44 +08:00

29 lines
723 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! QRGen 高纠错示例:生成可抵抗 30% 损坏的 QR 码
//!
//! 运行: `cargo run --example high_ecc`
use qr_core::qr::{QrCode, QrConfig, VersionMode};
use qr_core::version::EcLevel;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = QrConfig {
level: EcLevel::H, // 30% 纠错能力
version: VersionMode::Auto,
margin: 6, // 更大的静区
};
let qr = QrCode::encode("重要数据 - High ECC", config)?;
println!(
"版本: {}, 纠错: {:?}, 尺寸: {}×{}",
qr.version.0,
qr.level,
qr.size(),
qr.size()
);
let svg = qr.to_svg(None);
println!("SVG 生成成功: {} 字节", svg.len());
Ok(())
}