Closed Luni-4 closed 3 years ago
The format of the image must be in BGRA. See here https://docs.rs/iced_native/0.4.0/iced_native/widget/image/enum.Data.html#variant.Pixels
Oops, you're right, I missed that. Thank you! But I cannot understand why the Vector filled with 0 does not work though.
It would be helpful to add a RGBA/RGB APIs, more intuitive in my opinion. Or is there a particular reason not to have them?
I'm not sure why this format was chosen, but as to the image not displaying it's probably because the alpha value is also 0 so it's transparent.
@yusdacra
I followed your advice but it does not seem to work either this method
fn view(&mut self) -> Element<Message> {
let pixel_values: Vec<u8> = [0, 0, 0, 255]
.iter()
.cycle()
.take(4 * self.width * self.height)
.copied()
.collect();
let image_handle =
image::Handle::from_pixels(self.width as u32, self.height as u32, pixel_values);
image::Viewer::new(&mut self.image_viewer, image_handle)
.width(Length::Units(self.width as u16))
.height(Length::Units(self.height as u16))
.into()
}
Try to make every pixel 255, or just the alpha value 255.
Ouch, it's an u8
, not a floating point, I don't know why I've written that value. Edited the message above, perhaps it could be useful for someone else. It works perfectly now.
Thanks a lot for your help @yusdacra, very appreciated! :smile:
We can close this issue as invalid then
When I try to visualize a memory-mapped image, the application does not render it
Below there is a simple minimal test to better explain my problem
Cargo.toml
main.rs
I also tried to create different versions of the
view
function:Using an
Image
Creating the image externally through the
image
crateIf I instead try to load an external image
It works perfectly.
Thanks in advance for your help! :smiley: