55using OnnxStack . StableDiffusion . Common ;
66using OnnxStack . StableDiffusion . Config ;
77using OnnxStack . StableDiffusion . Enums ;
8+ using OnnxStack . StableDiffusion . Helpers ;
89using OnnxStack . StableDiffusion . Models ;
910using OnnxStack . UI . Commands ;
1011using OnnxStack . UI . Models ;
12+ using SixLabors . ImageSharp . PixelFormats ;
13+ using SixLabors . ImageSharp ;
1114using System ;
1215using System . Collections . Generic ;
1316using System . Collections . ObjectModel ;
@@ -385,7 +388,7 @@ private Action<DiffusionProgress> ProgressCallback()
385388 if ( progress . BatchTensor is not null )
386389 {
387390 PreviewResult = Utils . CreateBitmap ( progress . BatchTensor . ToImageBytes ( ) ) ;
388- PreviewSource = Utils . CreateBitmap ( _videoFrames . Frames [ progress . BatchValue - 1 ] ) ;
391+ PreviewSource = UpdatePreviewFrame ( progress . BatchValue - 1 ) ;
389392 ProgressText = $ "Video Frame { progress . BatchValue } of { _videoFrames . Frames . Count } complete";
390393 }
391394
@@ -402,6 +405,23 @@ private Action<DiffusionProgress> ProgressCallback()
402405 } ;
403406 }
404407
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+
405425 #region INotifyPropertyChanged
406426 public event PropertyChangedEventHandler PropertyChanged ;
407427 public void NotifyPropertyChanged ( [ CallerMemberName ] string property = "" )
0 commit comments