title: Resize image in WPF
body: <p>i have a image and i want to re size it and need to save in my temp folder. </p>
  
  <p>what i have tried is as below :</p>
  
  <pre><code>UIElement uie = CanvasHost.Child;
  int width = 800;
  int height = (int)((width / (double)((FrameworkElement)uie).Width) * (int)((FrameworkElement)uie).Height);          
  RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
  rtb.Render(uie);
  
  string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\temp\";
  if (!Directory.Exists(dir))
        Directory.CreateDirectory(dir);
  
  long size = 0;
  
  string filePath = dir + DateTime.Now.Ticks.ToString() + (isPng ? ".png" : ".jpg");
  BitmapEncoder enc = null;
  
  using (FileStream fs = File.Create(filePath))
  {
      if (isPng)
          enc = new PngBitmapEncoder();
      else
          enc = new JpegBitmapEncoder();
  
      enc.Frames.Add(BitmapFrame.Create(rtb));
      enc.Save(fs);
  
      size = fs.Length;
  }
  </code></pre>
  
  <p>but when i create image like this it saves part of the image in temp folder. (as shown in the above pic)</p>
  
  <p><img src="https://i.stack.imgur.com/hIfS2.jpg" alt="enter image description here"></p>
  
  <p>how can i re size full image? what i missed here?</p>
  
  <p><strong>EDIT :</strong>
  As mentioned in the above answer as mentioned by Erti-Chris Eelmaa i have changed the code as below. and it works...... </p>
  
  <pre><code>UIElement uie = CanvasHost.Child;
  int width = DataCache.Instance.CurrentProject.MaxPhotoEdgeSize;
  int height = (int)((width / (double)((FrameworkElement)uie).Width) * (int)((FrameworkElement)uie).Height);
  
  RenderTargetBitmap rtb = new RenderTargetBitmap((int)((FrameworkElement)uie).Width, (int)((FrameworkElement)uie).Height, 96, 96, PixelFormats.Pbgra32);
  rtb.Render(uie);
  
  ImageSource im = (ImageSource)rtb.Clone();
  BitmapFrame bp = CreateResizedImage(im, width, height, 1); //method suggested by Erti-Chris Eelmaa
  string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\temp\";
  
  if (!Directory.Exists(dir))
      Directory.CreateDirectory(dir);
  
  long size = 0;
  
  string filePath = dir + DateTime.Now.Ticks.ToString() + (isPng ? ".png" : ".jpg");
  BitmapEncoder enc = null;
  
  using (FileStream fs = File.Create(filePath))
  {
      if (isPng)
           enc = new PngBitmapEncoder();
      else
           enc = new JpegBitmapEncoder();
  
  
      enc.Frames.Add(BitmapFrame.Create(bp));
      enc.Save(fs);
  
      size = fs.Length;
  }
  </code></pre>