70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
using CamBooth.App.Core.AppSettings;
|
|
using CamBooth.App.Core.Logging;
|
|
using CamBooth.App.Features.Camera;
|
|
|
|
using EOSDigital.API;
|
|
|
|
namespace CamBooth.App.Features.LiveView;
|
|
|
|
public partial class LiveViewPage : Page
|
|
{
|
|
private readonly AppSettingsService _appSettings;
|
|
|
|
private readonly CameraService _cameraService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly ImageBrush bgbrush = new();
|
|
|
|
private readonly Action<BitmapImage> SetImageAction;
|
|
|
|
|
|
public LiveViewPage(Logger logger, AppSettingsService appSettings, CameraService cameraService)
|
|
{
|
|
this._logger = logger;
|
|
this._appSettings = appSettings;
|
|
this._cameraService = cameraService;
|
|
this.InitializeComponent();
|
|
this.SetImageAction = img => { this.bgbrush.ImageSource = img; };
|
|
|
|
// Mirror the LiveView image horizontally
|
|
ScaleTransform scaleTransform = new ScaleTransform(-1, 1, 0.5, 0.5);
|
|
this.bgbrush.Transform = scaleTransform;
|
|
|
|
this.LVCanvas.Background = this.bgbrush;
|
|
cameraService.ConnectCamera();
|
|
cameraService._mainCamera.LiveViewUpdated += this.MainCamera_OnLiveViewUpdated;
|
|
}
|
|
|
|
|
|
private void MainCamera_OnLiveViewUpdated(ICamera sender, Stream img)
|
|
{
|
|
try
|
|
{
|
|
using WrapStream s = new(img);
|
|
img.Position = 0;
|
|
BitmapImage EvfImage = new();
|
|
EvfImage.BeginInit();
|
|
EvfImage.StreamSource = s;
|
|
EvfImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
EvfImage.EndInit();
|
|
EvfImage.Freeze();
|
|
Application.Current.Dispatcher.BeginInvoke(this.SetImageAction, EvfImage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this._logger.Error(ex.Message);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this._cameraService.Dispose();
|
|
}
|
|
} |