Skip to content

Commit e41d6d7

Browse files
crop input image and clean up resources when change inputs
1 parent a836167 commit e41d6d7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Samples/StyleTransfer/AppViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public async Task SetModelSource()
137137
public async Task StartFilePick()
138138
{
139139
Debug.WriteLine("StartFilePick");
140+
InputSoftwareBitmapSource = new SoftwareBitmapSource();
141+
140142
try
141143
{
142144
// Load image to VideoFrame
@@ -172,13 +174,12 @@ public async Task ChangeFilePick()
172174

173175
private async Task EvaluateVideoFrameAsync()
174176
{
175-
InputSoftwareBitmapSource = new SoftwareBitmapSource();
176177
OutputSoftwareBitmapSource = new SoftwareBitmapSource();
177178

178179
if ((_appModel.InputFrame != null) &&
179180
(_appModel.InputFrame.SoftwareBitmap != null || _appModel.InputFrame.Direct3DSurface != null))
180181
{
181-
// _appModel.InputFrame = await ImageHelper.CenterCropImageAsync(inputVideoFrame, m_inWidth, m_inHeight);
182+
_appModel.InputFrame = await ImageHelper.CenterCropImageAsync(_appModel.InputFrame, m_inWidth, m_inHeight);
182183

183184
m_binding.Bind(m_inputImageDescription, ImageFeatureValue.CreateFromVideoFrame(_appModel.InputFrame));
184185
m_binding.Bind(m_outputImageDescription, ImageFeatureValue.CreateFromVideoFrame(_appModel.OutputFrame));
@@ -306,9 +307,6 @@ private async Task LoadModelAsync()
306307
m_inputImageDescription = m_model.InputFeatures.ToList().First().Name;
307308

308309
m_outputImageDescription = m_model.OutputFeatures.ToList().First().Name;
309-
310-
_appModel.OutputFrame?.Dispose();
311-
_appModel.OutputFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)m_outWidth, (int)m_outHeight);
312310
}
313311

314312
public void debugModelIO()
@@ -379,6 +377,8 @@ private void CleanupInputImage()
379377
InputSoftwareBitmapSource?.Dispose();
380378
OutputSoftwareBitmapSource?.Dispose();
381379

380+
_appModel.OutputFrame?.Dispose();
381+
_appModel.OutputFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)m_outWidth, (int)m_outHeight);
382382
}
383383

384384
public event PropertyChangedEventHandler PropertyChanged;

0 commit comments

Comments
 (0)