123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Avalonia.Interactivity;
- using Avalonia.Media.Imaging;
- using Avalonia.Threading;
- using HanumanInstitute.MvvmDialogs;
- using ReactiveUI;
- using System;
- using System.Threading.Tasks;
- using VeloeAvaloniaKemonoPartyApp.Models;
- namespace VeloeAvaloniaKemonoPartyApp.ViewModels
- {
- public class PostImageViewModel : ViewModelBase
- {
- private Attachment _attachment;
- private readonly IDialogService _dialogService;
- public PostImageViewModel(IDialogService dialogService,Attachment attachment)
- {
- _attachment = attachment;
- _dialogService = dialogService;
- }
- private Bitmap? _cover;
- public Bitmap? Cover
- {
- get => _cover;
- private set => this.RaiseAndSetIfChanged(ref _cover, value);
- }
- public async Task LoadAvatar()
- {
- await using (var imageStream = await _attachment.LoadCoverBitmapAsync())
- {
- if (imageStream is null) return;
- Cover = await Task.Run(() =>
- {
- Bitmap? bitmap;
- try
- {
- bitmap = new Bitmap(imageStream);
- bitmap = bitmap.CreateScaledBitmap(new Avalonia.PixelSize(bitmap.PixelSize.Width / 2, bitmap.PixelSize.Height / 2));
- }
- catch (Exception ex)
- {
- bitmap = null;
- }
- return bitmap;
- });
- }
- }
- public async Task OnImageClick(object sender, RoutedEventArgs e)
- {
- var vm = new ImageZoomViewModel(_attachment);
- _dialogService.Show((_dialogService.DialogManager as HanumanInstitute.MvvmDialogs.Avalonia.DialogManager).NavigationManager.CurrentViewModel, vm);
- }
- }
- }
|