我正在使用影像在 Rust 中打開和讀取影像。我使用 Windows Snipping 工具將螢屏截圖另存為影像,并嘗試打開它
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
如果我嘗試打開用手機拍攝的照片,效果很好。如何在 rust 中打開螢屏截圖?
uj5u.com熱心網友回復:
我能夠重現。這似乎是由于crate 版本中引入的錯誤。您不必手動操作影像,而應該簡單地使用以前的版本:png0.17.4
[dependencies]
image = "0.24.0"
png = "=0.17.3"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/434005.html
