title: UWP BitmapEncoder SetProperties is not supported
body: <p>So I'm creating a UWP app and need to write text and images to an image file and save them. I've currently created a D2D wrapper in C++ using <a href="https://code.msdn.microsoft.com/windowsapps/How-to-add-wartermark-f6313fad/view/SourceCode" rel="nofollow">this source</a> and then a C# wrapper that simply lets you access the functions of the C++ class in nice C# code (it does nothing else but access the WINMD C++ wrapper).</p>
  
  <p>However, after we write the image and text to the stream, we need to be able to save the file <b>with EXIF headers</b> containing info about rotation and location.</p>
  
  <p>We are using <code>encoder.BitmapProperties.SetPropertiesAsync</code> to accomplish this, but it returns:</p>
  
  <pre><code>Exception thrown: 'System.Exception' in Tester.exe
  
  Additional information: The operation is unsupported. (Exception from HRESULT: 0x88982F81)
  </code></pre>
  
  <p>There is no inner exception and the stack trace is:</p>
  
  <pre><code>   at Windows.Graphics.Imaging.BitmapEncoder.get_BitmapProperties()
     at Tester.ViewModels.&lt;_SaveImageWithPropertiesAsync&gt;d__56.MoveNext()
  </code></pre>
  
  <p>I want to try to avoid manually adding the headers, as I fear the returned stream from the D2DContext doesn't contain any header information or whatnot so it can't append anything to it.</p>
  
  <p>Here is the relevant part of my code:</p>
  
  <h2>C++</h2>
  
  <p>Again, you can find the original source <a href="https://code.msdn.microsoft.com/windowsapps/How-to-add-wartermark-f6313fad/view/SourceCode" rel="nofollow">here</a></p>
  
  <pre><code>IRandomAccessStream^ D2DWrapper::EndDraw()
  {
      DX::ThrowIfFailed(
          m_d2dContext-&gt;EndDraw()
      );
  
      // If needPreview is true, we return a valid IRandomAccessStream reference.
  
      GUID wicFormat = GUID_ContainerFormatBmp;
      ComPtr&lt;IStream&gt; stream;
      ComPtr&lt;ISequentialStream&gt; ss;
      auto inMemStream = ref new InMemoryRandomAccessStream();
      DX::ThrowIfFailed(
          CreateStreamOverRandomAccessStream(inMemStream, IID_PPV_ARGS(&amp;stream))
          );
  
      SaveBitmapToStream(m_targetBitmap, m_wicFactory, m_d2dContext, wicFormat, stream.Get());
  
      return inMemStream;
  
  }
  </code></pre>
  
  <h2>C# Wrapper</h2>
  
  <pre><code>public IRandomAccessStream EndDraw() {
      return _context.EndDraw()
  }
  </code></pre>
  
  <h2>C# Tester</h2>
  
  <pre><code>async Task _SaveImageWithPropertiesAsync(UWPImaging.Image image, PhotoOrientation photoOrientation)
  {
      var ras = await image.EndDraw();
  
      var decoder = await BitmapDecoder.CreateAsync(ras);
  
      var file = await KnownFolders.PicturesLibrary.CreateFileAsync(
          "test.jpeg",
          CreationCollisionOption.GenerateUniqueName);
  
      using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
      {
          var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
  
          var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(photoOrientation, PropertyType.UInt16) } };
  
          await encoder.BitmapProperties.SetPropertiesAsync(properties); // This is where the error occurs
  
          await encoder.FlushAsync();
      }
  }
  </code></pre>
  
  <p>Any help on how to get those headers in would be much appreciated!</p>
  
  <p>Thanks,</p>
  
  <h3>Nolan</h3>