ImageConverter.cs 835 B

123456789101112131415161718192021222324252627
  1. using Avalonia.Data.Converters;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Avalonia.Media.Imaging;
  9. using System.IO;
  10. using Avalonia.Platform;
  11. namespace AvaloniaApplication4.Converters
  12. {
  13. internal class ImageConverter : IValueConverter
  14. {
  15. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  16. {
  17. return value == null ? new Bitmap(AssetLoader.Open(new Uri("avares://AvaloniaApplication4/Assets/picture.png"))) : new Bitmap(new MemoryStream((byte[])value));
  18. }
  19. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  20. {
  21. throw new NotImplementedException();
  22. }
  23. }
  24. }