From e0ebb25f173455627a19b073eba2b6bf0da2429d Mon Sep 17 00:00:00 2001 From: Tobias Wohlleben Date: Mon, 20 Jan 2025 12:13:51 +0100 Subject: [PATCH] wip --- src/CamBooth/CamBooth.App/App.xaml.cs | 2 + .../CamBooth.App/Core/Camera/CameraService.cs | 316 ++++++++++++++++++ .../LiveView/LiveViewPage.xaml.cs | 266 +-------------- src/CamBooth/CamBooth.App/MainWindow.xaml.cs | 19 +- .../PictureGallery/PictureGalleryService.cs | 50 ++- ...icturePanel.xaml => PicturePanelPage.xaml} | 4 +- ...Panel.xaml.cs => PicturePanelPage.xaml.cs} | 24 +- src/CamBooth/CamBooth.sln.DotSettings.user | 1 + 8 files changed, 390 insertions(+), 292 deletions(-) create mode 100644 src/CamBooth/CamBooth.App/Core/Camera/CameraService.cs rename src/CamBooth/CamBooth.App/PictureGallery/{PicturePanel.xaml => PicturePanelPage.xaml} (85%) rename src/CamBooth/CamBooth.App/PictureGallery/{PicturePanel.xaml.cs => PicturePanelPage.xaml.cs} (58%) diff --git a/src/CamBooth/CamBooth.App/App.xaml.cs b/src/CamBooth/CamBooth.App/App.xaml.cs index c25cd24..1c75363 100644 --- a/src/CamBooth/CamBooth.App/App.xaml.cs +++ b/src/CamBooth/CamBooth.App/App.xaml.cs @@ -4,6 +4,7 @@ using System.Data; using System.Windows; using CamBooth.App.Core.AppSettings; +using CamBooth.App.Core.Camera; using CamBooth.App.Core.Logging; using CamBooth.App.DebugConsole; using CamBooth.App.LiveView; @@ -41,5 +42,6 @@ public partial class App : Application services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } } \ No newline at end of file diff --git a/src/CamBooth/CamBooth.App/Core/Camera/CameraService.cs b/src/CamBooth/CamBooth.App/Core/Camera/CameraService.cs new file mode 100644 index 0000000..c2b05df --- /dev/null +++ b/src/CamBooth/CamBooth.App/Core/Camera/CameraService.cs @@ -0,0 +1,316 @@ +using System.IO; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Threading; + +using CamBooth.App.Core.AppSettings; +using CamBooth.App.Core.Logging; +using CamBooth.App.LiveView; +using CamBooth.App.PictureGallery; + +using EOSDigital.API; +using EOSDigital.SDK; + +namespace CamBooth.App.Core.Camera; + +public class CameraService : IDisposable +{ + private readonly Logger _logger; + + private readonly AppSettingsService _appSettings; + + private readonly PictureGalleryService _pictureGalleryService; + + CanonAPI APIHandler; + + public EOSDigital.API.Camera MainCamera; + + bool IsInit = false; + + List CamList; + + CameraValue[] AvList; + + CameraValue[] TvList; + + CameraValue[] ISOList; + + int BulbTime = 30; + + int ErrCount; + + object ErrLock = new object(); + + + public CameraService(Logger logger, AppSettingsService appSettings, PictureGalleryService pictureGalleryService) + { + this._logger = logger; + this._appSettings = appSettings; + this._pictureGalleryService = pictureGalleryService; + try + { + APIHandler = new CanonAPI(); + IsInit = true; + } + catch (DllNotFoundException) + { + ReportError("Canon DLLs not found!", true); + } + catch (Exception ex) + { + ReportError(ex.Message, true); + } + } + + + public void ConnectCamera() + { + ErrorHandler.SevereErrorHappened += ErrorHandler_SevereErrorHappened; + ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened; + + RefreshCamera(); + List cameraList = this.APIHandler.GetCameraList(); + if (cameraList.Any()) + { + this.OpenSession(); + this.SetSettingSaveToComputer(); + this.StarLiveView(); + } + + string cameraDeviceNames = string.Join(", ", cameraList.Select(cam => cam.DeviceName)); + _logger.Info(cameraDeviceNames == string.Empty ? "No cameras / devices found" : cameraDeviceNames); + } + + + private void SetSettingSaveToComputer() + { + MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); + MainCamera.SetCapacity(4096, int.MaxValue); + } + + + public void CloseSession() + { + MainCamera.CloseSession(); + + // AvCoBox.Items.Clear(); + // TvCoBox.Items.Clear(); + // ISOCoBox.Items.Clear(); + // SettingsGroupBox.IsEnabled = false; + // LiveViewGroupBox.IsEnabled = false; + // SessionButton.Content = "Open Session"; + // SessionLabel.Content = "No open session"; + // StarLVButton.Content = "Start LV"; + } + + + private void RefreshCamera() + { + // CameraListBox.Items.Clear(); + CamList = APIHandler.GetCameraList(); + + // foreach (Camera cam in CamList) CameraListBox.Items.Add(cam.DeviceName); + // if (MainCamera?.SessionOpen == true) CameraListBox.SelectedIndex = CamList.FindIndex(t => t.ID == MainCamera.ID); + // else if (CamList.Count > 0) CameraListBox.SelectedIndex = 0; + } + + + private void OpenSession() + { + MainCamera = CamList[0]; + MainCamera.OpenSession(); + + //MainCamera.ProgressChanged += MainCamera_ProgressChanged; + MainCamera.StateChanged += MainCamera_StateChanged; + MainCamera.DownloadReady += MainCamera_DownloadReady; + + //SessionLabel.Content = MainCamera.DeviceName; + AvList = MainCamera.GetSettingsList(PropertyID.Av); + TvList = MainCamera.GetSettingsList(PropertyID.Tv); + ISOList = MainCamera.GetSettingsList(PropertyID.ISO); + + // foreach (var Av in AvList) AvCoBox.Items.Add(Av.StringValue); + // foreach (var Tv in TvList) TvCoBox.Items.Add(Tv.StringValue); + // foreach (var ISO in ISOList) ISOCoBox.Items.Add(ISO.StringValue); + // AvCoBox.SelectedIndex = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue); + // TvCoBox.SelectedIndex = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue); + // ISOCoBox.SelectedIndex = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue); + // SettingsGroupBox.IsEnabled = true; + // LiveViewGroupBox.IsEnabled = true; + } + + + private void ReportError(string message, bool lockdown) + { + int errc; + lock (ErrLock) + { + errc = ++ErrCount; + } + + if (lockdown) + { + //this.EnableUI(false); + } + + switch (errc) + { + case < 4: + this._logger.Info(message); + break; + case 4: + this._logger.Info("Many errors happened!"); + break; + } + + lock (ErrLock) + { + ErrCount--; + } + } + + + private void StarLiveView() + { + try + { + if (!MainCamera.IsLiveViewOn) + { + MainCamera.StartLiveView(); + } + else + { + MainCamera.StopLiveView(); + + //LVCanvas.Background = Brushes.LightGray; + } + } + catch (Exception ex) + { + ReportError(ex.Message, false); + } + } + + + #region API Events + + // private void APIHandler_CameraAdded(CanonAPI sender) + // { + // try + // { + // } + // catch (Exception ex) + // { + // ReportError(ex.Message, false); + // } + // } + + + private void MainCamera_StateChanged(EOSDigital.API.Camera sender, StateEventID eventID, int parameter) + { + try + { + if (eventID == StateEventID.Shutdown && IsInit) + { + Application.Current.Dispatcher.Invoke(() => this.CloseSession()); + + //Dispatcher.Invoke((Action)delegate { CloseSession(); }); + } + } + catch (Exception ex) + { + ReportError(ex.Message, false); + } + } + + + // private void MainCamera_ProgressChanged(object sender, int progress) + // { + // try + // { + // //MainProgressBar.Dispatcher.Invoke((Action)delegate { MainProgressBar.Value = progress; }); + // } + // catch (Exception ex) + // { + // ReportError(ex.Message, false); + // } + // } + + // private void MainCamera_LiveViewUpdated(EOSDigital.API.Camera sender, Stream img) + // { + // try + // { + // using (WrapStream s = new WrapStream(img)) + // { + // img.Position = 0; + // BitmapImage EvfImage = new BitmapImage(); + // EvfImage.BeginInit(); + // EvfImage.StreamSource = s; + // EvfImage.CacheOption = BitmapCacheOption.OnLoad; + // EvfImage.EndInit(); + // EvfImage.Freeze(); + // Application.Current.Dispatcher.BeginInvoke(SetImageAction, EvfImage); + // } + // } + // catch (Exception ex) + // { + // ReportError(ex.Message, false); + // } + // } + + + private void MainCamera_DownloadReady(EOSDigital.API.Camera sender, DownloadInfo Info) + { + this._logger.Info("MainCamera_DownloadReady called"); + try + { + string dir = this._appSettings.PictureLocation; + Info.FileName = $"img_{Guid.NewGuid().ToString()}.jpg"; + sender.DownloadFile(Info, dir); + this._logger.Info("Download complete: " + Path.Combine(dir, Info.FileName)); + Application.Current.Dispatcher.Invoke(() => { this._pictureGalleryService.LoadThumbnailsToCache(); }); + } + catch (Exception ex) + { + ReportError(ex.Message, false); + } + } + + + private void ErrorHandler_NonSevereErrorHappened(object sender, ErrorCode ex) + { + ReportError($"SDK Error code: {ex} ({((int)ex).ToString("X")})", false); + } + + + private void ErrorHandler_SevereErrorHappened(object sender, Exception ex) + { + ReportError(ex.Message, true); + } + + #endregion + + + public void TakePhoto() + { + try + { + MainCamera.TakePhotoAsync(); + } + catch (Exception ex) + { + ReportError(ex.Message, false); + } + } + + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + this.CloseSession(); + IsInit = false; + this.APIHandler.Dispose(); + this.MainCamera.Dispose(); + } +} \ No newline at end of file diff --git a/src/CamBooth/CamBooth.App/LiveView/LiveViewPage.xaml.cs b/src/CamBooth/CamBooth.App/LiveView/LiveViewPage.xaml.cs index 6fcba1f..d6c4ea9 100644 --- a/src/CamBooth/CamBooth.App/LiveView/LiveViewPage.xaml.cs +++ b/src/CamBooth/CamBooth.App/LiveView/LiveViewPage.xaml.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using CamBooth.App.Core.AppSettings; +using CamBooth.App.Core.Camera; using CamBooth.App.Core.Logging; using EOSDigital.API; @@ -20,218 +21,26 @@ public partial class LiveViewPage : Page private readonly AppSettingsService _appSettings; - CanonAPI APIHandler; - - Camera MainCamera; - - CameraValue[] AvList; - - CameraValue[] TvList; - - CameraValue[] ISOList; - - List CamList; - - bool IsInit = false; - - int BulbTime = 30; - - ImageBrush bgbrush = new ImageBrush(); - + private readonly CameraService _cameraService; + Action SetImageAction; - - int ErrCount; - - object ErrLock = new object(); - - - public LiveViewPage(Logger logger, AppSettingsService appSettings) + + private ImageBrush bgbrush = new ImageBrush(); + + public LiveViewPage(Logger logger, AppSettingsService appSettings, CameraService cameraService) { this._logger = logger; this._appSettings = appSettings; - try - { - InitializeComponent(); - APIHandler = new CanonAPI(); - ErrorHandler.SevereErrorHappened += ErrorHandler_SevereErrorHappened; - ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened; - - //SavePathTextBox.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto"); - SetImageAction = (BitmapImage img) => { bgbrush.ImageSource = img; }; - RefreshCamera(); - IsInit = true; - List cameraList = this.APIHandler.GetCameraList(); - if (cameraList.Any()) - { - this.OpenSession(); - this.StarLiveView(); - this.SetSettingSaveToComputer(); - } - - string cameraDeviceNames = string.Join(", ", cameraList.Select(cam => cam.DeviceName)); - logger.Info(cameraDeviceNames == string.Empty ? "No cameras / devices found" : cameraDeviceNames); - } - catch (DllNotFoundException) - { - ReportError("Canon DLLs not found!", true); - } - catch (Exception ex) - { - ReportError(ex.Message, true); - } - } - - private void SetSettingSaveToComputer() - { - MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); - MainCamera.SetCapacity(4096, int.MaxValue); - } - - public void CloseSession() - { - MainCamera.CloseSession(); - - // AvCoBox.Items.Clear(); - // TvCoBox.Items.Clear(); - // ISOCoBox.Items.Clear(); - // SettingsGroupBox.IsEnabled = false; - // LiveViewGroupBox.IsEnabled = false; - // SessionButton.Content = "Open Session"; - // SessionLabel.Content = "No open session"; - // StarLVButton.Content = "Start LV"; + this._cameraService = cameraService; + InitializeComponent(); + SetImageAction = (BitmapImage img) => { bgbrush.ImageSource = img; }; + LVCanvas.Background = bgbrush; + cameraService.ConnectCamera(); + cameraService.MainCamera.LiveViewUpdated += MainCamera_OnLiveViewUpdated; } - private void RefreshCamera() - { - // CameraListBox.Items.Clear(); - CamList = APIHandler.GetCameraList(); - - // foreach (Camera cam in CamList) CameraListBox.Items.Add(cam.DeviceName); - // if (MainCamera?.SessionOpen == true) CameraListBox.SelectedIndex = CamList.FindIndex(t => t.ID == MainCamera.ID); - // else if (CamList.Count > 0) CameraListBox.SelectedIndex = 0; - } - - - private void OpenSession() - { - MainCamera = CamList[0]; - MainCamera.OpenSession(); - MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated; - //MainCamera.ProgressChanged += MainCamera_ProgressChanged; - MainCamera.StateChanged += MainCamera_StateChanged; - MainCamera.DownloadReady += MainCamera_DownloadReady; - - //SessionLabel.Content = MainCamera.DeviceName; - AvList = MainCamera.GetSettingsList(PropertyID.Av); - TvList = MainCamera.GetSettingsList(PropertyID.Tv); - ISOList = MainCamera.GetSettingsList(PropertyID.ISO); - - // foreach (var Av in AvList) AvCoBox.Items.Add(Av.StringValue); - // foreach (var Tv in TvList) TvCoBox.Items.Add(Tv.StringValue); - // foreach (var ISO in ISOList) ISOCoBox.Items.Add(ISO.StringValue); - // AvCoBox.SelectedIndex = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue); - // TvCoBox.SelectedIndex = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue); - // ISOCoBox.SelectedIndex = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue); - // SettingsGroupBox.IsEnabled = true; - // LiveViewGroupBox.IsEnabled = true; - } - - - private void ReportError(string message, bool lockdown) - { - int errc; - lock (ErrLock) - { - errc = ++ErrCount; - } - - if (lockdown) - { - //this.EnableUI(false); - } - - switch (errc) - { - case < 4: - this._logger.Info(message); - break; - case 4: - this._logger.Info("Many errors happened!"); - break; - } - - lock (ErrLock) - { - ErrCount--; - } - } - - private void StarLiveView() - { - try - { - if (!MainCamera.IsLiveViewOn) - { - LVCanvas.Background = bgbrush; - MainCamera.StartLiveView(); - } - else - { - MainCamera.StopLiveView(); - LVCanvas.Background = Brushes.LightGray; - } - } - catch (Exception ex) - { - ReportError(ex.Message, false); - } - } - - #region API Events - - // private void APIHandler_CameraAdded(CanonAPI sender) - // { - // try - // { - // } - // catch (Exception ex) - // { - // ReportError(ex.Message, false); - // } - // } - - - private void MainCamera_StateChanged(Camera sender, StateEventID eventID, int parameter) - { - try - { - if (eventID == StateEventID.Shutdown && IsInit) - { - Dispatcher.Invoke((Action)delegate { CloseSession(); }); - } - } - catch (Exception ex) - { - ReportError(ex.Message, false); - } - } - - - // private void MainCamera_ProgressChanged(object sender, int progress) - // { - // try - // { - // //MainProgressBar.Dispatcher.Invoke((Action)delegate { MainProgressBar.Value = progress; }); - // } - // catch (Exception ex) - // { - // ReportError(ex.Message, false); - // } - // } - - - private void MainCamera_LiveViewUpdated(Camera sender, Stream img) + private void MainCamera_OnLiveViewUpdated(Camera sender, Stream img) { try { @@ -249,58 +58,19 @@ public partial class LiveViewPage : Page } catch (Exception ex) { - ReportError(ex.Message, false); + _logger.Error(ex.Message); } } - private void MainCamera_DownloadReady(Camera sender, DownloadInfo Info) - { - this._logger.Info("MainCamera_DownloadReady called"); - try - { - string dir = this._appSettings.PictureLocation; - sender.DownloadFile(Info, dir); - this._logger.Info("Download complete: " + Path.Combine(dir, Info.FileName)); - //MainProgressBar.Dispatcher.Invoke((Action)delegate { MainProgressBar.Value = 0; }); - } - catch (Exception ex) - { - ReportError(ex.Message, false); - } - } - - private void ErrorHandler_NonSevereErrorHappened(object sender, ErrorCode ex) - { - ReportError($"SDK Error code: {ex} ({((int)ex).ToString("X")})", false); - } - - - private void ErrorHandler_SevereErrorHappened(object sender, Exception ex) - { - ReportError(ex.Message, true); - } - - #endregion - - public void TakePhoto() { - try - { - MainCamera.TakePhotoAsync(); - } - catch (Exception ex) - { - ReportError(ex.Message, false); - } + this._cameraService.TakePhoto(); } + public void Dispose() { - this.CloseSession(); - IsInit = false; - MainCamera?.Dispose(); - APIHandler?.Dispose(); + this._cameraService.Dispose(); } } \ No newline at end of file diff --git a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs index d158c5d..ae7d47c 100644 --- a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs +++ b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using CamBooth.App.Core.AppSettings; +using CamBooth.App.Core.Camera; using CamBooth.App.Core.Logging; using CamBooth.App.DebugConsole; using CamBooth.App.LiveView; @@ -21,6 +22,8 @@ public partial class MainWindow : Window private readonly PictureGalleryService _pictureGalleryService; + private readonly CameraService _cameraService; + private bool _isDebugConsoleVisible = true; private bool _isPicturePanelVisible = false; @@ -28,11 +31,15 @@ public partial class MainWindow : Window private LiveViewPage? _liveViewPage; - public MainWindow(Logger logger, AppSettingsService appSettings, PictureGalleryService pictureGalleryService) + public MainWindow(Logger logger, + AppSettingsService appSettings, + PictureGalleryService pictureGalleryService, + CameraService cameraService) { this._logger = logger; this._appSettings = appSettings; this._pictureGalleryService = pictureGalleryService; + this._cameraService = cameraService; InitializeComponent(); this.SetVisibilityDebugConsole(this._isDebugConsoleVisible); this.LoadPicturePanelAsync(); @@ -44,9 +51,9 @@ public partial class MainWindow : Window private void LoadPicturePanelAsync() { - //this.PicturePanel.Visibility = Visibility.Hidden; - //this.PicturePanel.Navigate(new PicturePanel(this._appSettings, this._logger)); - this._pictureGalleryService.LoadThumbnailsToCache(12); + //this.PicturePanelPage.Visibility = Visibility.Hidden; + //this.PicturePanelPage.Navigate(new PicturePanelPage(this._appSettings, this._logger)); + this._pictureGalleryService.LoadThumbnailsToCache(); //this.DebugFrame.Navigate(new DebugConsolePage(this._logger)); } @@ -55,7 +62,7 @@ public partial class MainWindow : Window { if (visibility) { - this.PicturePanel.Navigate(new PicturePanel(this._appSettings, this._logger, this._pictureGalleryService)); + this.PicturePanel.Navigate(new PicturePanelPage(this._appSettings, this._logger, this._pictureGalleryService)); } else { @@ -74,7 +81,7 @@ public partial class MainWindow : Window private void NavToLiveView(object sender, RoutedEventArgs e) { - _liveViewPage = new LiveViewPage(this._logger, this._appSettings); + _liveViewPage = new LiveViewPage(this._logger, this._appSettings, this._cameraService); MainFrame.Navigate(this._liveViewPage); } diff --git a/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs b/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs index 458edb1..9add697 100644 --- a/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs +++ b/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs @@ -15,22 +15,12 @@ public class PictureGalleryService private readonly Logger _logger; - public List ImageControls - { - get - { - // List tmp = new List(); - // foreach (var image in imageControls) - // { - // tmp.Add(image); - // } - // return tmp; - - return this.imageControls; - } - } + public List ThumbnailsOrderedByNewestDescending => this.thumbnails. + OrderByDescending(map => map.Key) + .Select(ordered => ordered.Value) + .ToList(); - private List imageControls = new List(); + private Dictionary thumbnails = new(); public PictureGalleryService(AppSettingsService appSettings, Logger logger) @@ -40,30 +30,32 @@ public class PictureGalleryService } - public void LoadThumbnailsToCache(int howManyPictures) + public void LoadThumbnailsToCache(int cacheSize = 0) { + this._logger.Info("Start load thumbnails into cache"); string? pictureLocation = this._appSettings.PictureLocation; int loop = 0; - var picturePaths = Directory.EnumerateFiles(pictureLocation).ToList(); + + List picturePaths = Directory.EnumerateFiles(pictureLocation).ToList(); + do { string picturePath = picturePaths[loop]; - this._logger.Info("load image: " + picturePath); - var imageControl = new Wpf.Ui.Controls.Image() + DateTime creationTime = File.GetCreationTime(picturePath); + + // add if not exists + if (!this.thumbnails.ContainsKey(creationTime)) { - Source = CreateThumbnail(picturePath, 244, 200), - Width = 386, // Optional: Setze Breite - Margin = new Thickness(3) // Optional: Abstand zwischen Bildern - }; - - - // Füge das Image-Control in ein StackPanel ein - this.imageControls.Add(imageControl); + this.thumbnails.Add(creationTime, CreateThumbnail(picturePath, 244, 200)); + this._logger.Info($"Thumbnail '{picturePath}' successfully created"); + } loop++; } - while (loop < howManyPictures && loop < picturePaths.Count); + while ((loop < cacheSize || cacheSize == 0) && loop < picturePaths.Count); + + this._logger.Info("Loading thumbnails into cache completed"); } public static BitmapImage CreateThumbnail(string filePath, int maxWidth, int maxHeight) @@ -71,7 +63,7 @@ public class PictureGalleryService var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(filePath); - bitmap.DecodePixelWidth = maxWidth; // Größe des Thumbnails direkt beim Dekodieren festlegen + bitmap.DecodePixelWidth = maxWidth; // Größe des ThumbnailsOrderedByNewestDescending direkt beim Dekodieren festlegen bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); return bitmap; diff --git a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml similarity index 85% rename from src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml rename to src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml index f86a4dc..e8e0daf 100644 --- a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml +++ b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml @@ -1,11 +1,11 @@ - diff --git a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml.cs similarity index 58% rename from src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs rename to src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml.cs index ba324fa..cc41c5d 100644 --- a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs +++ b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanelPage.xaml.cs @@ -10,7 +10,7 @@ using Image = Wpf.Ui.Controls.Image; namespace CamBooth.App.PictureGallery; -public partial class PicturePanel : Page, IDisposable +public partial class PicturePanelPage : Page, IDisposable { private readonly AppSettingsService _appSettingsService; @@ -19,7 +19,7 @@ public partial class PicturePanel : Page, IDisposable private readonly PictureGalleryService _pictureGalleryService; - public PicturePanel(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService) + public PicturePanelPage(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService) { this._appSettingsService = appSettingsService; this._logger = logger; @@ -42,15 +42,25 @@ public partial class PicturePanel : Page, IDisposable } - private void LoadPictures(int howManyPictures) + private void LoadPictures(int howManyPictures = 0) { - foreach (Image ctl in this._pictureGalleryService.ImageControls) + int loop = 0; + + do { - if(!this.PicturesPanel.Children.Contains(ctl)) + BitmapImage thumbnail = this._pictureGalleryService.ThumbnailsOrderedByNewestDescending[loop]; + + var imageControl = new Wpf.Ui.Controls.Image() { - this.PicturesPanel.Children.Add(ctl); - } + Source = thumbnail, + Width = 388, + Margin = new Thickness(3) + }; + + this.PicturesPanel.Children.Add(imageControl); + loop++; } + while ((loop < howManyPictures || howManyPictures == 0) && loop < this._pictureGalleryService.ThumbnailsOrderedByNewestDescending.Count); } diff --git a/src/CamBooth/CamBooth.sln.DotSettings.user b/src/CamBooth/CamBooth.sln.DotSettings.user index af2df7e..d63f4c5 100644 --- a/src/CamBooth/CamBooth.sln.DotSettings.user +++ b/src/CamBooth/CamBooth.sln.DotSettings.user @@ -7,6 +7,7 @@ True True ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file