【问题标题】:What is the correct way to print images using WPF DocumentPaginator使用 WPF DocumentPaginator 打印图像的正确方法是什么
【发布时间】:2015-10-08 05:18:52
【问题描述】:

这是我在扩展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 对象的正确方法是什么?

【问题讨论】:

  • 我看过那个帖子...FixedPageDocumentPage 不同。
  • 您是否尝试过该答案中的代码来创建BitmapImage 实例?
  • 是的。它对输出没有影响。
  • GetPagePath 方法有什么作用?

标签: c# wpf image documentpaginator


【解决方案1】:

您必须调用 Image 控件的 Measure()Arrange() 方法来进行布局:

var image = new Image { Source = source };
var size = new Size(source.PixelWidth, source.PixelHeight);
image.Measure(size);
image.Arrange(new Rect(size));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-20
    • 2017-07-28
    • 1970-01-01
    • 2016-11-16
    • 2010-10-09
    • 2011-04-01
    • 2011-05-17
    相关资源
    最近更新 更多