using Avalar.Services.Interfaces; using Avalonia.Media.Imaging; using ImageMagick; using ReactiveUI; using System; using System.Threading; namespace Avalar.Services { public class ImageMagickResizer : ReactiveObject, IResizer { private uint m_Width; public uint Width { get => m_Width; set => this.RaiseAndSetIfChanged(ref m_Width, value); } private uint m_Height; public uint Height { get => m_Height; set => this.RaiseAndSetIfChanged(ref m_Height, value); } public IBitmap Process(IBitmap input, CancellationToken token) { using var image = input.ToMagickImage(); var geometry = new MagickGeometry(Convert.ToInt32(Width), Convert.ToInt32(Height)); geometry.IgnoreAspectRatio = true; image.Resize(geometry); return image.ToBitmap(); } } }