File tree 1 file changed +7
-0
lines changed
1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -495,25 +495,32 @@ mod frame_capture {
495
495
}
496
496
if !image_data. is_empty ( ) {
497
497
for image in images_to_save. iter ( ) {
498
+ // Fill correct data from channel to image
498
499
let img_bytes = images. get_mut ( image. id ( ) ) . unwrap ( ) ;
499
500
img_bytes. data . clone_from ( & image_data) ;
500
501
502
+ // Create RGBA Image Buffer
501
503
let img = match img_bytes. clone ( ) . try_into_dynamic ( ) {
502
504
Ok ( img) => img. to_rgba8 ( ) ,
503
505
Err ( e) => panic ! ( "Failed to create image buffer {e:?}" ) ,
504
506
} ;
505
507
508
+ // Prepare directory for images, test_images in bevy folder is used here for example
509
+ // You should choose the path depending on your needs
506
510
let images_dir =
507
511
PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "test_images" ) ;
508
512
info ! ( "Saving image to: {images_dir:?}" ) ;
509
513
std:: fs:: create_dir_all ( & images_dir) . unwrap ( ) ;
510
514
515
+ // Search for the first unoccupied number
511
516
let mut number = 0 ;
512
517
let mut image_path = images_dir. join ( format ! ( "{number:03}.png" ) ) ;
513
518
while image_path. exists ( ) {
514
519
number += 1 ;
515
520
image_path = images_dir. join ( format ! ( "{number:03}.png" ) ) ;
516
521
}
522
+
523
+ // Finally saving image to file
517
524
if let Err ( e) = img. save ( image_path) {
518
525
panic ! ( "Failed to save image: {}" , e) ;
519
526
} ;
You can’t perform that action at this time.
0 commit comments