I'm rather new to Rust and playing around with resizing images using turbojpeg, since it's rather quick.
This is basically what I'm doing:
//read jpeg from disc
let jpeg_data = std::fs::read(img_path_in).unwrap();
//decompress jpeg image data as Image<Vec<u8>>
let img = turbojpeg::decompress(&jpeg_data,turbojpeg::PixelFormat::RGB).unwrap();
//convert image data to be able to resize image
let img_to_resize = img.as_deref().pixels;
//compress the image data as jpeg
let jpeg_data_out = turbojpeg::compress(img_resized, 75, turbojpeg::Subsamp::Sub2x2).unwrap();
//save jpeg to file
I have been using the resize create to try and resize the image data, which seem to work, but how do I go about converting the resized image data, which is of type Vec<u8>, to Image<&[u8]> that turbojpeg::compress() accepts?
I might be doing something fundamentally wrong here, and therefor asking the wrong question so feel free to contribute to solving the problem instead of answering my question.
You may have accidentally imported the unstable SlicePattern trait as a code completion for as_slice. Just delete the import of the trait, there's an inherent as_slice method on Vec and that's the one you want.
Ha, that was funny. It would have taken me a while to figure that one out.
After removing use core::slice::SlicePattern; it works, thank you.
(It doesn't really work but it compiles so I can fix the rest)