Files
GSS2Rework/GSS2.UI.Core/ViewModels/AsyncImageViewModel.cs
T
amkovkov 3cc4d21947 feat: massive rework
1) GSS2.Core:
- strip prefixes in GSS2.Core.Analysis.AmineContent namespace class names
- add IEnumerable<double>.Variance extension
- remake analysis + update database so not needed to store all every file, calibration data also stored in database, also currently capturing images stored in system temporary directory and rewriting every time
2) GSS.UI.Core: AsyncImageRecordViewModel make zoom and pans public
3) GSS:
- remove image-storage-clear command
- remove ResultsView and ResultsViewModel, results presented in analysis
- rework calibration views
- add analysis views
- add text and number fields editors view
- add confirmation view on danger buttons
2026-05-13 12:56:32 +03:00

49 lines
1.3 KiB
C#

using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GSS2.UI.Core.ViewModels;
public partial class AsyncImageRecordViewModel : ViewModelBase
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
[ObservableProperty] public partial string Path { get; set; }
[ObservableProperty] public partial IImage? Image { get; set; }
[ObservableProperty] public partial bool IsLoading { get; set; } = true;
public AsyncImageRecordViewModel(string path)
{
Path = path;
}
partial void OnPathChanged(string value) => _ = LoadAsync();
private async Task LoadAsync()
{
await _semaphore.WaitAsync();
try
{
var bitmap = await Task.Run(() => new Bitmap(Path));
await Dispatcher.UIThread.InvokeAsync(() =>
{
Image = bitmap;
IsLoading = false;
});
}
catch (Exception ex)
{
Console.Error.WriteLine($"Ошибка во время загрузки изображения:\n{ex.Message}\n{ex.StackTrace}");
await Dispatcher.UIThread.InvokeAsync(() => IsLoading = false);
}
finally
{
_semaphore.Release();
}
}
}