为什么在使用 image crate 时会出现 `DuplicateChunk` 解码错误?

Why do I get a `DuplicateChunk` decoding error when using the image crate?

我正在使用 image 在 Rust 中打开和读取图像。 我使用 Windows 截图工具将屏幕截图另存为图像,并尝试打开它

let image_path = "C:/Users/mason/rust-projects/image-test/image.png";
let image = image::open(image_path).unwrap();
let _ = image;

但我收到错误消息:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Decoding(DecodingError { format: Exact(Png), underlying: Some(Format(FormatError { inner: DuplicateChunk { kind: ChunkType { type: gAMA, critical: false, private: false, reserved: false, safecopy: false } } })) })', src\main.rs:82:12
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/30b3f35c420694a4f24e5a4df00f06073f4f3a37\/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/30b3f35c420694a4f24e5a4df00f06073f4f3a37\/library\core\src\panicking.rs:143
   2: core::result::unwrap_failed
             at /rustc/30b3f35c420694a4f24e5a4df00f06073f4f3a37\/library\core\src\result.rs:1749
   3: enum$<core::result::Result<enum$<image::dynimage::DynamicImage>,enum$<image::error::ImageError> > >::unwrap<enum$<image::dynimage::DynamicImage>,enum$<image::error::ImageError> >
             at /rustc/30b3f35c420694a4f24e5a4df00f06073f4f3a37\library\core\src\result.rs:1065
   4: image_test::main
             at .\src\main.rs:3
   5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/30b3f35c420694a4f24e5a4df00f06073f4f3a37\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\image-test.exe` (exit code: 101)

Process finished with exit code 101

如果我尝试打开我用 phone 拍摄的照片,它工作正常。 如何在 Rust 中打开屏幕截图?

我能够重现。这似乎是由于 png 板条箱版本 0.17.4 中引入的 a bug。您不必手动操作图像,而应该简单地使用以前的版本:

[dependencies]
image = "0.24.0"
png = "=0.17.3"