简体   繁体   English

无法消费 Rgba<u8> (无方法)在 Rust</u8>

[英]Unable to consume Rgba<u8> (no methods) in Rust

let png = image::open("src/heightmaps/ALPSMLC30_N050E014_DSM_8_BIT.png").unwrap();
    for p in png.pixels() {
        let p: image::Rgba<u8> = p.2;
    }

p is (u32, u32, image::Rgba<u8>) . p 是(u32, u32, image::Rgba<u8>) What I don't know is how to access the u8 out of Rgba (the VSCode doesn't find any methods for it).我不知道如何从Rgba访问u8 (VSCode 没有找到任何方法)。 How do I proceed?我该如何进行? Here is the link to the Rgba struct: https://docs.rs/image/0.23.13/image/struct.Rgba.html .这是 Rgba 结构的链接: https://docs.rs/image/0.23.13/image/struct.Rgba.html

image::Rgba is a tuple struct, you can access fields of a tuple struct using struct.0 syntax or more ergonomically through destructuring: image::Rgba 是一个元组结构,您可以使用struct.0语法或更符合人体工程学的方式通过解构来访问元组结构的字段:

let png = image::open("src/heightmaps/ALPSMLC30_N050E014_DSM_8_BIT.png").unwrap();
for (_, _, image::Rgba(p)) in png.pixels() {
    let [r, g, b, a] = p;
}

Looking at the definition for image::Rgba<T> , it appears that the only field is public so you should be able to just access it directly.查看image::Rgba<T>的定义,似乎唯一的字段是公共的,因此您应该能够直接访问它。

Eg with verbsoe destructuring:例如用动词解构:

let png = image::open("src/heightmaps/ALPSMLC30_N050E014_DSM_8_BIT.png").unwrap();
for p in png.pixels() {
    let p: image::Rgba<u8> = p.2;
    let rgba: [u8;4] = p.0;
    let [r,g,b,a] = rgba;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM