首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用WPF DocumentPaginator打印图像的正确方式是什么?

使用WPF DocumentPaginator打印图像的正确方式是什么?
EN

Stack Overflow用户
提问于 2015-10-08 01:50:00
回答 1查看 733关注 0票数 0

下面是我在一个扩展DocumentPaginator的类中的代码

代码语言:javascript
复制
    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对象的正确方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2015-10-08 05:13:34

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

代码语言:javascript
复制
var image = new Image { Source = source };
var size = new Size(source.PixelWidth, source.PixelHeight);
image.Measure(size);
image.Arrange(new Rect(size));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32999118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档