这是我在扩展类中的代码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);
}
但是,当我实际运行此代码时,它似乎并没有加载我的图像,而只是打印空白页。
加载图像并将其附加到DocumentPage
对象的正确方法是什么?