1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using Avalonia.Media.Imaging;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using VeloeAvaloniaKemonoPartyApp.Models;
- namespace VeloeAvaloniaKemonoPartyApp.ViewModels
- {
- public class CreatorViewModel : ViewModelBase
- {
- private readonly Creator _creator;
- public CreatorViewModel(Creator creator)
- {
- _creator = creator;
- }
- public string Artist => _creator.name;
- public string Title => _creator.updated.ToString();
- private Bitmap? _cover;
- public Bitmap? Cover
- {
- get => _cover;
- private set => this.RaiseAndSetIfChanged(ref _cover, value);
- }
- public async Task LoadCover()
- {
- await using (var imageStream = await _creator.LoadCoverBitmapAsync())
- {
- Cover = await Task.Run(() =>
- {
- Bitmap? bitmap;
- try
- {
- bitmap = new Bitmap(imageStream);
- }
- catch (Exception ex)
- {
- bitmap = null;
- }
- return bitmap;
- });
- }
- }
- public async Task SaveToDiskAsync()
- {
- await _creator.SaveAsync();
- if (Cover != null)
- {
- var bitmap = Cover;
- await Task.Run(() =>
- {
- using (var fs = _creator.SaveCoverBitmapStream())
- {
- bitmap.Save(fs);
- }
- });
- }
- }
- }
- }
|