Kenneth Schmidt
Kenneth Schmidt

Reputation: 55

Rust open image with other format than file extension

I am trying to open an image in my Rust program. The image is named foo.png, but it won't open the image with image::open("foo.png"). If I rename the file to foo.jpeg, I can open the image, so my guess is that the formatting and the file extension do not match.

My question is then. how do I open a file named foo.png, but decode it as a jpeg? I have tried image::io::Reader, but I can't seem to make it work properly.

Upvotes: 2

Views: 1567

Answers (1)

Brian Bowman
Brian Bowman

Reputation: 941

You can use the image::load() function, which lets you specify the format:

let image = image::load(BufReader::new(File::open("foo.png")?), ImageFormat::Jpeg)?;

Upvotes: 2

Related Questions