5
5
using OnnxStack . StableDiffusion . Common ;
6
6
using OnnxStack . StableDiffusion . Config ;
7
7
using OnnxStack . StableDiffusion . Enums ;
8
+ using OnnxStack . StableDiffusion . Helpers ;
8
9
using OnnxStack . StableDiffusion . Models ;
9
10
using OnnxStack . UI . Commands ;
10
11
using OnnxStack . UI . Models ;
12
+ using SixLabors . ImageSharp . PixelFormats ;
13
+ using SixLabors . ImageSharp ;
11
14
using System ;
12
15
using System . Collections . Generic ;
13
16
using System . Collections . ObjectModel ;
@@ -385,7 +388,7 @@ private Action<DiffusionProgress> ProgressCallback()
385
388
if ( progress . BatchTensor is not null )
386
389
{
387
390
PreviewResult = Utils . CreateBitmap ( progress . BatchTensor . ToImageBytes ( ) ) ;
388
- PreviewSource = Utils . CreateBitmap ( _videoFrames . Frames [ progress . BatchValue - 1 ] ) ;
391
+ PreviewSource = UpdatePreviewFrame ( progress . BatchValue - 1 ) ;
389
392
ProgressText = $ "Video Frame { progress . BatchValue } of { _videoFrames . Frames . Count } complete";
390
393
}
391
394
@@ -402,6 +405,23 @@ private Action<DiffusionProgress> ProgressCallback()
402
405
} ;
403
406
}
404
407
408
+ public BitmapImage UpdatePreviewFrame ( int index )
409
+ {
410
+ var frame = _videoFrames . Frames [ index ] ;
411
+ using ( var memoryStream = new MemoryStream ( ) )
412
+ using ( var frameImage = SixLabors . ImageSharp . Image . Load < Rgba32 > ( frame ) )
413
+ {
414
+ ImageHelpers . Resize ( frameImage , new [ ] { 1 , 3 , _schedulerOptions . Height , _schedulerOptions . Width } ) ;
415
+ frameImage . SaveAsPng ( memoryStream ) ;
416
+ var image = new BitmapImage ( ) ;
417
+ image . BeginInit ( ) ;
418
+ image . CacheOption = BitmapCacheOption . OnLoad ;
419
+ image . StreamSource = memoryStream ;
420
+ image . EndInit ( ) ;
421
+ return image ;
422
+ }
423
+ }
424
+
405
425
#region INotifyPropertyChanged
406
426
public event PropertyChangedEventHandler PropertyChanged ;
407
427
public void NotifyPropertyChanged ( [ CallerMemberName ] string property = "" )
0 commit comments