mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:46:30 +00:00
57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace Azaion.Annotator.DTO;
|
|
|
|
public class ThumbnailDto : INotifyPropertyChanged
|
|
{
|
|
public string ThumbnailPath { get; set; }
|
|
public string ImagePath { get; set; }
|
|
public string LabelPath { get; set; }
|
|
|
|
private BitmapImage? _image;
|
|
public BitmapImage? Image
|
|
{
|
|
get
|
|
{
|
|
if (_image == null)
|
|
LoadImageAsync();
|
|
return _image;
|
|
}
|
|
set
|
|
{
|
|
_image = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
private async void LoadImageAsync()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var bitmap = new BitmapImage();
|
|
bitmap.BeginInit();
|
|
bitmap.UriSource = new Uri(ThumbnailPath);
|
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
|
bitmap.DecodePixelWidth = 480;
|
|
bitmap.DecodePixelHeight = 270;
|
|
bitmap.EndInit();
|
|
bitmap.Freeze(); // Freeze to make it cross-thread accessible
|
|
Image = bitmap;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
} |