title: WPF - Black Background surrounding saved canvas as jpeg
body: <p>I'm having difficulty with JpegBitmapEncoder since it is creating an image that is placed in black rectangle. and I don't have the solution for fix.</p>
  
  <pre><code> private void SaveImage(Canvas canvas, string fileName)
      {
          SaveFileDialog s = new SaveFileDialog();
          s.FileName = "Pic";
          s.DefaultExt = ".jpg";
          s.Filter = "JPG files (.jpg)|*.jpg";
  
          Nullable&lt;bool&gt; result = s.ShowDialog();
          if (result == true)
          {
              RenderTargetBitmap renderBitmap = new RenderTargetBitmap(6646, 3940, 2000d, 2000d, PixelFormats.Pbgra32);
  
              canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
              canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));
  
              renderBitmap.Render(canvas);
  
              string filename = s.FileName;
              JpegBitmapEncoder encoder = new JpegBitmapEncoder();
              encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
  
              using (FileStream file = File.Create(filename))
              {
                  encoder.Save(file);
              }
          }
      }
  </code></pre>
  
  <p>with this code i get:</p>
  
  <p><a href="https://i.stack.imgur.com/TvcP4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TvcP4.jpg" alt="enter image description here"></a></p>
  
  <p>but when i use PngBitmap Encoder this doesn't happen. Can anyone shine a light?
  How do I remove the black rectangle or perhaps fill it by increasing the dimensions of the picture?</p>