以下是我在扩展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
对象的正确方法是什么?
答案 0 :(得分:0)
您必须通过调用Measure()
和Arrange()
方法来执行Image控件的布局:
var image = new Image { Source = source };
var size = new Size(source.PixelWidth, source.PixelHeight);
image.Measure(size);
image.Arrange(new Rect(size));