0

Here is my code that is in a class extending DocumentPaginator

    public override DocumentPage GetPage(int pageNumber)
    {
        BitmapImage source = new BitmapImage();
        using (Stream stream = new FileStream(GetPagePath(pageNumber), FileMode.Open))
        {
            source.BeginInit();
            source.StreamSource = stream;
            source.CacheOption = BitmapCacheOption.OnLoad;
            source.EndInit();
        }

        var image = new Image { Source = source };

        Rect contentBox = new Rect(PageSize);

        return new DocumentPage(image, PageSize, contentBox, contentBox);
    }

However when I actually run this code, it doesn't seem to load my image and merely prints blank pages.

What is the correct way to load my image and attach it to a DocumentPage object?

theycallmemorty
  • 12,515
  • 14
  • 51
  • 71

1 Answers1

0

You must do the layout of the Image control by calling its Measure() and Arrange() methods:

var image = new Image { Source = source };
var size = new Size(source.PixelWidth, source.PixelHeight);
image.Measure(size);
image.Arrange(new Rect(size));
Clemens
  • 123,504
  • 12
  • 155
  • 268