Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // Bind to byte Array from your ObservableCollection and use Converter so it will convert the image to a byte array
  2.  
  3. class ImageConverter : IValueConverter
  4. {
  5. public object Convert(object value, Type targetType, object parameter, string language)
  6. {
  7. if (value == null || !(value is byte[]))
  8. return null;
  9. using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
  10. {
  11. using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
  12. {
  13. writer.WriteBytes((byte[])value);
  14. writer.StoreAsync().GetResults();
  15. }
  16. var image = new BitmapImage();
  17. image.SetSource(ms);
  18. return image;
  19. }
  20. }
  21.  
  22. public object ConvertBack(object value, Type targetType, object parameter, string language)
  23. {
  24. throw new NotImplementedException();
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement