实现加载图像到实时图像区

This commit is contained in:
zhengxuan.zhang
2026-04-20 11:35:40 +08:00
parent e0a7af6226
commit 8c78f805e6
10 changed files with 147 additions and 104 deletions
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using Prism.Events;
using Prism.Commands;
using Prism.Mvvm;
using System;
@@ -9,6 +10,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using XP.Common.Logging.Interfaces;
using XplorePlane.Events;
using XplorePlane.Models;
using XplorePlane.Services;
@@ -22,6 +24,7 @@ namespace XplorePlane.ViewModels
private readonly IImageProcessingService _imageProcessingService;
private readonly IPipelineExecutionService _executionService;
private readonly IPipelinePersistenceService _persistenceService;
private readonly IEventAggregator _eventAggregator;
private readonly ILoggerService _logger;
private PipelineNodeViewModel _selectedNode;
@@ -40,11 +43,13 @@ namespace XplorePlane.ViewModels
IImageProcessingService imageProcessingService,
IPipelineExecutionService executionService,
IPipelinePersistenceService persistenceService,
IEventAggregator eventAggregator,
ILoggerService logger)
{
_imageProcessingService = imageProcessingService ?? throw new ArgumentNullException(nameof(imageProcessingService));
_executionService = executionService ?? throw new ArgumentNullException(nameof(executionService));
_persistenceService = persistenceService ?? throw new ArgumentNullException(nameof(persistenceService));
_eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
_logger = logger?.ForModule<PipelineEditorViewModel>() ?? throw new ArgumentNullException(nameof(logger));
PipelineNodes = new ObservableCollection<PipelineNodeViewModel>();
@@ -64,6 +69,9 @@ namespace XplorePlane.ViewModels
OpenToolboxCommand = new DelegateCommand(OpenToolbox);
MoveNodeUpCommand = new DelegateCommand<PipelineNodeViewModel>(MoveNodeUp);
MoveNodeDownCommand = new DelegateCommand<PipelineNodeViewModel>(MoveNodeDown);
_eventAggregator.GetEvent<ManualImageLoadedEvent>()
.Subscribe(OnManualImageLoaded);
}
// ── State Properties ──────────────────────────────────────────
@@ -306,6 +314,7 @@ namespace XplorePlane.ViewModels
PreviewImage = result;
StatusMessage = "流水线执行完成";
PublishPipelinePreviewUpdated(result, StatusMessage);
}
catch (OperationCanceledException)
{
@@ -362,6 +371,45 @@ namespace XplorePlane.ViewModels
SourceImage = bitmap;
PreviewImage = bitmap;
StatusMessage = $"已加载图像:{Path.GetFileName(filePath)}";
PublishManualImageLoaded(bitmap, filePath);
}
internal void LoadImageFromBitmap(BitmapSource bitmap, string filePath, bool runPipeline = true)
{
if (bitmap == null)
throw new ArgumentNullException(nameof(bitmap));
SourceImage = bitmap;
PreviewImage = bitmap;
StatusMessage = $"已加载图像:{Path.GetFileName(filePath)}";
PublishManualImageLoaded(bitmap, filePath);
if (runPipeline)
TriggerDebouncedExecution();
}
private void PublishManualImageLoaded(BitmapSource bitmap, string filePath)
{
_eventAggregator.GetEvent<ManualImageLoadedEvent>()
.Publish(new ManualImageLoadedPayload(bitmap, filePath));
}
private void PublishPipelinePreviewUpdated(BitmapSource bitmap, string statusMessage)
{
if (bitmap == null) return;
_eventAggregator.GetEvent<PipelinePreviewUpdatedEvent>()
.Publish(new PipelinePreviewUpdatedPayload(bitmap, statusMessage));
}
private void OnManualImageLoaded(ManualImageLoadedPayload payload)
{
if (payload?.Image == null) return;
if (ReferenceEquals(SourceImage, payload.Image)) return;
SourceImage = payload.Image;
PreviewImage = payload.Image;
StatusMessage = $"已加载图像:{payload.FileName}";
}
private void CancelExecution()