1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.UI/Screens/Workshop/Image/ImageSubmissionViewModel.cs
2023-10-29 20:43:30 +01:00

42 lines
1.3 KiB
C#

using System.IO;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using System.Windows.Input;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Image;
public partial class ImageSubmissionViewModel : ActivatableViewModelBase
{
[Notify(Setter.Private)] private Bitmap? _bitmap;
[Notify(Setter.Private)] private string? _fileName;
[Notify(Setter.Private)] private string? _imageDimensions;
[Notify(Setter.Private)] private long _fileSize;
[Notify] private ICommand? _remove;
public ImageSubmissionViewModel(Stream imageStream)
{
this.WhenActivated(d =>
{
Dispatcher.UIThread.Invoke(() =>
{
imageStream.Seek(0, SeekOrigin.Begin);
Bitmap = new Bitmap(imageStream);
FileSize = imageStream.Length;
ImageDimensions = Bitmap.Size.Width + "x" + Bitmap.Size.Height;
if (imageStream is FileStream fileStream)
FileName = Path.GetFileName(fileStream.Name);
else
FileName = "Unnamed image";
Bitmap.DisposeWith(d);
}, DispatcherPriority.Background);
});
}
}