Rust image crate分形示例编译错误及依赖疑问求助
Hey there! Let's tackle your two problems step by step:
1. Fixing the save Method Compilation Error
That error pops up because the save method in newer versions of the image crate no longer accepts a second format parameter. The API was updated to automatically infer the image format from the file extension in your output path (fout).
To fix this, simply remove the image::PNG argument from the save call:
image::ImageLuma8(imgbuf).save(fout).unwrap();
If you need to explicitly specify the format (for cases where the file extension doesn't match the desired format, or there's no extension at all), use the save_with_format method instead:
image::ImageLuma8(imgbuf).save_with_format(fout, image::PNG).unwrap();
This change comes from API improvements in the image crate—older examples might not have been updated to reflect this breaking change, which is why your rustc 1.25.0 build is throwing an error.
2. Understanding the num_complex Import Change
You’re totally correct to adjust that import! The standalone num_complex crate was merged into the larger num crate some time ago, and it’s no longer maintained as a separate package in the mainstream Rust ecosystem.
Your modified import use num::complex::Complex; is the correct way to access the Complex type now. Just make sure your Cargo.toml includes the num dependency (instead of num_complex) like this:
[dependencies] num = "0.4" # Use the latest version compatible with your Rust 1.25.0 toolchain image = "0.23" # Match a version that works with Rust 1.25.0
内容的提问来源于stack exchange,提问作者TC29

