0

これがクラス拡張にある私のコードです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画像を読み込んでオブジェクトに添付する正しい方法は何ですか?

4

1 に答える 1

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));
于 2015-10-07T21:13:33.820 に答える