Rust open png always as grayscale

I am aware of https://docs.rs/png/0.15.3/png/index.html
and the decoder example there.

Is there a way to tell Rust to always open the image as grayscale? I'm trying to avoid complicated modes like Indexed

I'm now convinced there's no obvious way to do this via png crate, and the simplest solution is to use the image crate: https://docs.rs/image/0.22.4/image/enum.DynamicImage.html#method.grayscale

I’m not aware of a way to force it to load as grayscale initially either. I’ve been using to_luma to get a GrayImage, which could be useful if you don’t want to introduce colours later:

https://docs.rs/image/0.23.0-preview.0/image/enum.DynamicImage.html#method.to_luma

1 Like

Your solution is definitely better, as mine provides a DynamicImage, whereas yours provides a GrayImage

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