It takes a full 30 seconds to turn it into grey scale!
use image::{DynamicImage, GenericImageView, ImageFormat};
use std::io::{Cursor, Write};
#[flutter_rust_bridge::frb(sync)]
pub fn bytes(bytes: Vec) -> Vec {
// Load image from bytes
let image = match image::load_from_memory(&bytes) {
Ok(img) => img,
Err(_) => panic!("Failed to load image from bytes"),
};
// Convert image to grayscale
let img_gray = image.grayscale();
// Encode grayscale image as JPEG into a buffer
let mut result_bytes = Vec::new();
let mut cursor = Cursor::new(&mut result_bytes);
img_gray.write_to(&mut cursor, ImageFormat::Jpeg)
.expect("Failed to encode image as JPEG");
// Flush the cursor to ensure all data is written to result_bytes
cursor.flush().expect("Failed to flush cursor");
result_bytes
}