12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Avalonia.Media.Imaging;
- using ReactiveUI;
- using System;
- using System.Threading.Tasks;
- using VeloeAvaloniaKemonoPartyApp.Models;
- namespace VeloeAvaloniaKemonoPartyApp.ViewModels
- {
- public class PostImageViewModel : ViewModelBase
- {
- private Attachment _attachment;
- public PostImageViewModel(Attachment attachment)
- {
- _attachment = attachment;
- }
- 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;
- });
- }
- }
- }
- }
|