Display image with minifb

When running the minifb examples with --example image the included images in the resources directory display perfectly. When I copy my own PNG file into that directory and attempt to display it, the result is
Screenshot_2020-02-15_21-59-44
Source image is this:
rerustedlogo
How do I troubleshoot this as I'm sure it's something to do with the nature of the PNG file I'm using.

Your image's color space is RGBA not RGB.
So you should change example code to use 4 chunks to decode image.
e.g:

let u32_buffer: Vec<u32> = buf
        .chunks(4) // 3 -> 4
        .map(|v| ((v[0] as u32) << 16) | ((v[1] as u32) << 8) | v[2] as u32)
        .collect();

update_with_buffer treat each pixel as 0RGB and ignores upper 8-bit.
So we can only use RGB channel.

1 Like

Brilliant. Thank you so much.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.