Skip to content

Commit

Permalink
Interaction with file system has been commented
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsweeper committed May 5, 2024
1 parent 5c8e54b commit 08c6aff
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/app/headless_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,25 +495,32 @@ mod frame_capture {
}
if !image_data.is_empty() {
for image in images_to_save.iter() {
// Fill correct data from channel to image
let img_bytes = images.get_mut(image.id()).unwrap();
img_bytes.data.clone_from(&image_data);

// Create RGBA Image Buffer
let img = match img_bytes.clone().try_into_dynamic() {
Ok(img) => img.to_rgba8(),
Err(e) => panic!("Failed to create image buffer {e:?}"),
};

// Prepare directory for images, test_images in bevy folder is used here for example
// You should choose the path depending on your needs
let images_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_images");
info!("Saving image to: {images_dir:?}");
std::fs::create_dir_all(&images_dir).unwrap();

// Search for the first unoccupied number
let mut number = 0;
let mut image_path = images_dir.join(format!("{number:03}.png"));
while image_path.exists() {
number += 1;
image_path = images_dir.join(format!("{number:03}.png"));
}

// Finally saving image to file
if let Err(e) = img.save(image_path) {
panic!("Failed to save image: {}", e);
};
Expand Down

0 comments on commit 08c6aff

Please sign in to comment.