title: How to change Image file formats
body: <p>I want to write an application that takes an image(jpeg, png, tiff, gif,...) as stream and convert it to jrx(jpeg xr) with lossless compression.</p>
  
  <p>Thats is what i have tried so far with no useable result:</p>
  
  <pre><code>using System.Windows.Media.Imaging;
      //decode jpg
      public static BitmapSource ReadJpeg(Stream imageStreamSource)
      {
          JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
          BitmapSource bitmapSource = decoder.Frames[0];
          return bitmapSource;
      }
      //encode
      public static Stream Encode(BitmapSource image)
      {
          WmpBitmapEncoder encoder = new WmpBitmapEncoder();
          MemoryStream s = new MemoryStream();
          encoder.Frames.Add(BitmapFrame.Create(image));
          encoder.Save(s);
          return s;
      }
  </code></pre>
  
  <p>Can someone point me in the right direction? I am hanging here for some time now.</p>
  
  <p>If you need more informations please ask.</p>
  
  <p><a href="https://stackoverflow.com/questions/13469631/system-drawing-bitmap-to-jpeg-xr">System.Drawing.Bitmap to JPEG XR</a> is working for the given input formats but doesnt fully cover my question because the part of decoding the image is missing.</p>
  
  <p>Thank you all for pointing me in the right direction!
  I do know now, how to proceed. </p>