title: Convert a RenderTargetBitmap to BitmapImage
body: <p>How can I convert a RenderTargetBitmap to BitmapImage in C# XAML, Windows 8.1?</p>
  
  <p>I tried </p>
  
  <pre><code>// rendered is the RenderTargetBitmap 
  BitmapImage img = new BitmapImage();
  InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
  await randomAccessStream.WriteAsync(await rendered.GetPixelsAsync());
  randomAccessStream.Seek(0); 
  await img.SetSourceAsync(randomAccessStream);
  </code></pre>
  
  <p>But it always gives error at </p>
  
  <pre><code>img.SetSourceAsync(randomAccessStream);
  </code></pre>
  
  <p>There are many ways in WPF but in WinRT? How can I do that ?</p>
  
  <p>Thanks a lot!</p>