| Crates.io | thumbcache |
| lib.rs | thumbcache |
| version | 0.4.0 |
| created_at | 2024-08-27 13:08:49.228683+00 |
| updated_at | 2025-05-13 11:38:29.745003+00 |
| description | Get file thumbnail on Windows |
| homepage | https://github.com/yhdgms1/thumbcache |
| repository | https://github.com/yhdgms1/thumbcache |
| max_upload_size | |
| id | 1353373 |
| size | 12,113 |
Uses Windows thumbcache to get bmp preview for a file.
When trying to get preview from file that is not an image (.zip or .exe) will result in error.
use std::io::{Error, Write};
pub fn main() -> Result<(), Error> {
let bmp = thumbcache::get_bmp(r"C:\path-to-file.jpeg", thumbcache::ThumbSize::S96)?;
let mut file_out = std::fs::File::create("./out.bmp")?;
let _ = file_out.write_all(&bmp);
Ok(())
}
Windows can only return BMP, but this format may not always be convenient. In this example, BMP is converted to JPEG using image crate.
use thumbcache::{get_bmp};
use image::{load_from_memory};
fn main() {
let bmp = get_bmp(r"C:\path-to-file.jpeg", thumbcache::ThumbSize::S256).unwrap();
let image = load_from_memory(&bmp).unwrap();
let mut buf: Vec<u8> = Vec::new();
let mut writer = std::io::Cursor::new(&mut buf);
image.write_to(&mut writer, image::ImageFormat::Jpeg).unwrap();
std::fs::write("./output.jpeg", buf).unwrap();
}
https://stackoverflow.com/questions/14207618/get-bytes-from-hbitmap
https://stackoverflow.com/questions/21751747/extract-thumbnail-for-any-file-in-windows