This commit is contained in:
iTob 2025-01-19 18:25:10 +01:00
parent 2ff3758596
commit 1287af3314
9 changed files with 258 additions and 38 deletions

View File

@ -1,8 +1,14 @@
<Application x:Class="CamBooth.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:CamBooth.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Light" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -7,6 +7,7 @@ using CamBooth.App.Core.AppSettings;
using CamBooth.App.Core.Logging;
using CamBooth.App.DebugConsole;
using CamBooth.App.LiveView;
using CamBooth.App.PictureGallery;
using Microsoft.Extensions.DependencyInjection;
@ -39,5 +40,6 @@ public partial class App : Application
services.AddTransient<MainWindow>();
services.AddSingleton<Logger>();
services.AddSingleton<AppSettingsService>();
services.AddSingleton<PictureGalleryService>();
}
}

View File

@ -25,6 +25,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
<PackageReference Include="WPF-UI" Version="4.0.0-rc.3" />
</ItemGroup>
<ItemGroup>

View File

@ -65,7 +65,7 @@ public partial class LiveViewPage : Page
{
this.OpenSession();
this.StarLiveView();
this.SetCameraSaveToComputer();
this.SetSettingSaveToComputer();
}
string cameraDeviceNames = string.Join(", ", cameraList.Select(cam => cam.DeviceName));
@ -81,7 +81,7 @@ public partial class LiveViewPage : Page
}
}
private void SetCameraSaveToComputer()
private void SetSettingSaveToComputer()
{
MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
MainCamera.SetCapacity(4096, int.MaxValue);

View File

@ -3,15 +3,20 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:CamBooth.App"
mc:Ignorable="d"
Title="MainWindow" Width="1600" Height="900" HorizontalAlignment="Stretch">
Title="MainWindow"
Background="Black"
Width="1600" Height="900"
HorizontalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/> <!-- Erste Zeile (Auto-Höhe) -->
<RowDefinition Height="Auto"/> <!-- Zweite Zeile (flexibler Platz) -->
<RowDefinition Height="Auto"/> <!-- Dritte Zeile (Auto-Höhe) -->
<RowDefinition Height="*" /> <!-- Erste Zeile (Auto-Höhe) -->
<RowDefinition Height="Auto" /> <!-- Zweite Zeile (flexibler Platz) -->
<RowDefinition Height="Auto" /> <!-- Dritte Zeile (flexibler Platz) -->
<RowDefinition Height="Auto" /> <!-- Dritte Zeile (Auto-Höhe) -->
</Grid.RowDefinitions>
<!-- Inhalt der ersten Zeile -->
@ -32,13 +37,29 @@
HorizontalAlignment="Center"
Background="LightGreen"
VerticalAlignment="Bottom"
Panel.ZIndex="2" />
<!-- Inhalt der dritten Zeile (nimmt den verbleibenden Platz ein) -->
<Frame Grid.Row="1"
x:Name="PicturePanel"
Margin="5"
NavigationUIVisibility="Hidden"
HorizontalAlignment="Center"
Background="Blue"
VerticalAlignment="Bottom"
Panel.ZIndex="1" />
<!-- Inhalt der dritten Zeile -->
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 5 5">
<Button Content="Start" Click="NavToLiveView" Width="200" Background="LightCoral" Height="50" VerticalAlignment="Bottom"/>
<Button Content="Hide Debug" Click="ToggleDebugConsole" Width="200" Background="LightCoral" Height="50" VerticalAlignment="Bottom"/>
<Button Content="Take Photo" Click="TakePhoto" Width="200" Background="LightCoral" Height="50" VerticalAlignment="Bottom"/>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0 0 5 5">
<ui:Button Content="Start" Click="NavToLiveView" Width="200" Height="50" VerticalAlignment="Bottom"
Margin="0 0 5 5" />
<ui:Button Content="Hide Debug" Click="SetVisibilityDebugConsole" Width="200" Height="50"
VerticalAlignment="Bottom" Margin="0 0 5 5" />
<ui:Button Content="Take Photo" Click="TakePhoto" Width="200" Height="50" VerticalAlignment="Bottom"
Margin="0 0 5 5" />
<ui:Button Content="Pictures" Click="SetVisibilityPicturePanel" Width="200" Height="50"
VerticalAlignment="Bottom" Margin="0 0 5 5" />
</StackPanel>
</Grid>

View File

@ -1,10 +1,12 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using CamBooth.App.Core.AppSettings;
using CamBooth.App.Core.Logging;
using CamBooth.App.DebugConsole;
using CamBooth.App.LiveView;
using CamBooth.App.PictureGallery;
namespace CamBooth.App;
@ -17,23 +19,56 @@ public partial class MainWindow : Window
private readonly AppSettingsService _appSettings;
private bool _isDebugConsoleVisible;
private readonly PictureGalleryService _pictureGalleryService;
private LiveViewPage _liveViewPage;
private bool _isDebugConsoleVisible = true;
public MainWindow(Logger logger, AppSettingsService appSettings)
private bool _isPicturePanelVisible = false;
private LiveViewPage? _liveViewPage;
public MainWindow(Logger logger, AppSettingsService appSettings, PictureGalleryService pictureGalleryService)
{
this._logger = logger;
this._appSettings = appSettings;
this._pictureGalleryService = pictureGalleryService;
InitializeComponent();
ToggleDebugConsole();
this.SetVisibilityDebugConsole(this._isDebugConsoleVisible);
this.LoadPicturePanelAsync();
this.SetVisibilityPicturePanel(this._isPicturePanelVisible);
this.Closing += OnClosing;
logger.Info("MainWindow initialized");
}
private void LoadPicturePanelAsync()
{
//this.PicturePanel.Visibility = Visibility.Hidden;
//this.PicturePanel.Navigate(new PicturePanel(this._appSettings, this._logger));
Task.Run(() => this._pictureGalleryService.LoadThumbnailsToCache(12));
//this.DebugFrame.Navigate(new DebugConsolePage(this._logger));
}
private void SetVisibilityPicturePanel(bool visibility)
{
if (visibility)
{
this.PicturePanel.Navigate(new PicturePanel(this._appSettings, this._logger, this._pictureGalleryService));
}
else
{
this.PicturePanel.ClearValue(MainWindow.ContentProperty);
}
this._isPicturePanelVisible = !visibility;
}
private void OnClosing(object? sender, CancelEventArgs e)
{
this._liveViewPage.Dispose();
this._liveViewPage?.Dispose();
}
@ -43,27 +78,36 @@ public partial class MainWindow : Window
MainFrame.Navigate(this._liveViewPage);
}
private void ToggleDebugConsole(object sender, RoutedEventArgs e)
private void SetVisibilityDebugConsole(object sender, RoutedEventArgs e)
{
this.ToggleDebugConsole();
this.SetVisibilityDebugConsole(this._isDebugConsoleVisible);
}
private void ToggleDebugConsole()
private void SetVisibilityDebugConsole(bool visibility)
{
if (_isDebugConsoleVisible)
{
this.DebugFrame.ClearValue(MainWindow.ContentProperty);
}
else
if (visibility)
{
this.DebugFrame.Navigate(new DebugConsolePage(this._logger));
}
this._isDebugConsoleVisible = !this._isDebugConsoleVisible;
else
{
this.DebugFrame.ClearValue(MainWindow.ContentProperty);
}
this._isDebugConsoleVisible = !visibility;
}
private void TakePhoto(object sender, RoutedEventArgs e)
{
this._liveViewPage.TakePhoto();
this._liveViewPage?.TakePhoto();
}
private void SetVisibilityPicturePanel(object sender, RoutedEventArgs e)
{
this.SetVisibilityPicturePanel(this._isPicturePanelVisible);
}
}

View File

@ -0,0 +1,78 @@
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using CamBooth.App.Core.AppSettings;
using CamBooth.App.Core.Logging;
using Wpf.Ui.Controls;
namespace CamBooth.App.PictureGallery;
public class PictureGalleryService
{
private readonly AppSettingsService _appSettings;
private readonly Logger _logger;
public List<Image> ImageControls
{
get
{
List<Image> tmp = new List<Image>();
foreach (var image in imageControls)
{
tmp.Add(image);
}
return tmp;
}
}
public List<Image> imageControls = new List<Image>();
public PictureGalleryService(AppSettingsService appSettings, Logger logger)
{
this._appSettings = appSettings;
this._logger = logger;
}
public void LoadThumbnailsToCache(int howManyPictures)
{
string? pictureLocation = this._appSettings.PictureLocation;
int loop = 0;
var picturePaths = Directory.EnumerateFiles(pictureLocation).ToList();
do
{
string picturePath = picturePaths[loop];
this._logger.Info("load image: " + picturePath);
var imageControl = new Wpf.Ui.Controls.Image()
{
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);
loop++;
}
while (loop < howManyPictures && loop < picturePaths.Count);
}
public static BitmapImage CreateThumbnail(string filePath, int maxWidth, int maxHeight)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(filePath);
bitmap.DecodePixelWidth = maxWidth; // Größe des Thumbnails direkt beim Dekodieren festlegen
// bitmap.DecodePixelHeight = maxHeight;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
return bitmap;
}
}

View File

@ -0,0 +1,16 @@
<Page x:Class="CamBooth.App.PictureGallery.PicturePanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CamBooth.App.PictureGallery"
mc:Ignorable="d"
Title="PicturePanel" Width="1600" Height="795"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Background="Magenta">
<Grid>
<ScrollViewer VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<WrapPanel VerticalAlignment="Stretch" x:Name="PicturesPanel" Orientation="Horizontal" />
</ScrollViewer>
</Grid>
</Page>

View File

@ -0,0 +1,52 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using CamBooth.App.Core.AppSettings;
using CamBooth.App.Core.Logging;
using Image = Wpf.Ui.Controls.Image;
namespace CamBooth.App.PictureGallery;
public partial class PicturePanel : Page
{
private readonly AppSettingsService _appSettingsService;
private readonly Logger _logger;
private readonly PictureGalleryService _pictureGalleryService;
public PicturePanel(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService)
{
this._appSettingsService = appSettingsService;
this._logger = logger;
this._pictureGalleryService = pictureGalleryService;
InitializeComponent();
this.Initialize();
}
private void Initialize()
{
try
{
LoadPictures(12);
}
catch (Exception e)
{
this._logger.Info(e.Message);
}
}
private void LoadPictures(int howManyPictures)
{
foreach (Image ctl in this._pictureGalleryService.ImageControls)
{
this.PicturesPanel.Children.Add(ctl);
}
}
}