ByteToImageConverter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace GDNXFD.Alert.Config.Converters
  2. {
  3. using System;
  4. using System.IO;
  5. using System.Windows.Data;
  6. using System.Windows.Media.Imaging;
  7. /// <summary>
  8. /// Byte to image converter
  9. /// </summary>
  10. public class ByteToImageConverter : IValueConverter
  11. {
  12. /// <summary>
  13. /// Convert a byte array to an image.
  14. /// </summary>
  15. /// <param name="value"></param>
  16. /// <param name="targetType"></param>
  17. /// <param name="parameter"></param>
  18. /// <param name="culture"></param>
  19. /// <returns></returns>
  20. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  21. {
  22. if (value != null)
  23. {
  24. BitmapImage bi = new BitmapImage();
  25. bi.BeginInit();
  26. bi.StreamSource = new MemoryStream((byte[])value);
  27. bi.EndInit();
  28. return bi;
  29. }
  30. return null;
  31. }
  32. /// <summary>
  33. /// Convert an image to a byte array
  34. /// </summary>
  35. /// <param name="value"></param>
  36. /// <param name="targetType"></param>
  37. /// <param name="parameter"></param>
  38. /// <param name="culture"></param>
  39. /// <returns></returns>
  40. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. }