aisop/src/SopHelper.Avalonia/VVMs/RecipeEditor/StepKeyFrameViewModel.cs

29 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Prism.Commands;
namespace SopHelper.VVMs.RecipeEditor;
public partial class RecipeEditorViewModel
{
public DelegateCommand CaptureStepKeyFrameCommand { get; }
private string _stepKeyFrameStatus = "";
public string StepKeyFrameStatus { get => _stepKeyFrameStatus; private set => SetProperty(ref _stepKeyFrameStatus, value); }
private void CaptureStepKeyFrame()
{
if (Recipe.SelectedStep is not { } step) { StepKeyFrameStatus = "请先选中一个步骤。"; return; }
var recording = SopRecording;
if (IsAgentBusy || IsCapturing || recording is { IsTestingFlow: true }
|| recording?.Playback.IsSeeking == true || StepEditorImage is not { } frame)
{ StepKeyFrameStatus = "请先播放标准视频;等待跳转完成后再获取关键帧,流程测试时不可取图。"; return; }
try
{
// UI线程同步取得已显示帧,避免按秒数重新解码造成图像与用户所见不一致。
var bytes = frame.ToPngBytes();
step.KeyFrameBase64 = Convert.ToBase64String(bytes);
step.KeyFrameSeconds = ReferenceEquals(frame, recording?.Playback.Frame) ? recording!.Playback.DisplayedSeconds : null;
StepKeyFrameStatus = $"已获取步骤 {step.Id}「{step.Name}」关键帧,请保存配方。";
}
catch (Exception) { StepKeyFrameStatus = "关键帧保存失败,请重新获取。"; }
}
}