using System.Collections.Generic; using System.IO; using Avalonia.Media.Imaging; using CommunityToolkit.Mvvm.ComponentModel; using GazpromApp.Models; namespace GazpromApp.ViewModels; public partial class ImageViewModel : ViewModelBase { [ObservableProperty] private byte[]? _bytes; // EF stuff [ObservableProperty] private List? _points; [ObservableProperty] private List? _equipment; [ObservableProperty] private Bitmap? _fileName; public ImageViewModel(Image image) { Bytes = image.Bytes; Equipment = image.Equipment; Points = image.Points; FileName = image.Bytes is { Length: > 0 } ? new Bitmap(new MemoryStream(image.Bytes)) : null; } public ImageViewModel() { Bytes = null; Equipment = null; Points = null; } public Image GetImage() { var ms = new MemoryStream(); FileName?.Save(ms); return new Image { Bytes = ms.ToArray(), Equipment = Equipment ?? [], Points = Points ?? [] }; } }