title: Synchronous way to convert byte array to image in Windows Phone 8.1
body: <p>I have a StorageFile with serialized music information which I deserialize when starting the app. I need to store albumart picture, but because BitmapImage can't be serialized I use a byte array. I want to bind the byte array (which is part of a ObservableCollection) to the Source of an image. For this to work I need to convert the byte array to a BitmapImage using an IValueConverter.</p>
  
  <p>My problem is that an IValueConverter is a synchronous method and I can't seem to find a synchronous way to convert a byte array in a BitmapImage...</p>
  
  <p>I tried this:</p>
  
  <pre><code>byte[] imagedata = tag.Pictures[0].PictureData;
  Debug.WriteLine("Byte array length: " + imagedata.Length.ToString());
  
  using (MemoryStream ms = new MemoryStream(imagedata))
  {
      // create IRandomAccessStream
      var albumartstream = ms.AsRandomAccessStream();
      albumartstream.Seek(0);
  
      // create bitmap and assign
      BitmapImage albumart = new BitmapImage();
      albumart.SetSourceAsync(albumartstream);
  
      // return
      return albumart;
  }
  </code></pre>
  
  <p>This throws an exception:</p>
  
  <pre><code>The application called an interface that was marshalled for a different thread
  </code></pre>
  
  <p>The only way to solve this is to use a Dispatcher which makes the code asynchronous and therefor incompatible with the IValueConverter...</p>
  
  <p>What should I do to make this work?</p>