title: Printing and scaling images in WPF
body: <p>I am trying to print an image with a title using WPF.</p>
  
  <p>In the raw form (I am taking the image from an on-screen control which in turn fetches it from a database), the image is larger than the page so I need to scale it.</p>
  
  <p>I would like the title at the top of the page (I may want to also add more lines to the title) and then the image scaled to fit the remaining page area (whilst maintaining the aspect ratio). I also want the page to be oriented correctly based upon the orientation of the image.</p>
  
  <p>The code I have so far (pilfered from various pages)...</p>
  
  <pre><code>PrintDialog printDialog = new PrintDialog();
  printDialog.PrintTicket.PageOrientation = this.image.ActualWidth &gt; this.image.ActualHeight ? PageOrientation.Landscape : PageOrientation.Portrait;
  
  if (printDialog.ShowDialog() == true) {
  
      Size size = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
      StackPanel stackPanel = new StackPanel { Orientation = Orientation.Vertical, RenderSize = size };
  
      TextBlock title = new TextBlock { Text = @"Form", FontSize = 20 };
      stackPanel.Children.Add(title);
  
      Image image = new Image { Source = this.image.Source, Stretch = Stretch.Uniform };
      image.RenderTransform = new ScaleTransform(1, 1);
      stackPanel.Children.Add(image);
  
      stackPanel.Measure(size);
      stackPanel.Arrange(new Rect(new Point(0, 0), stackPanel.DesiredSize));
  
      printDialog.PrintVisual(stackPanel, @"Form image");
  
  }
  </code></pre>
  
  <p>Problem is, the image is always too big and the text in the title is not printed correctly (I am just seeing a few vertical lines). I know my problem is in the way I am setting sizes and/or scaling but I just cannot see it.</p>
  
  <p>Any suggestions?</p>