他のUIElementsで画像を印刷できるようにしたい。FixedPageインスタンスがあり、そのような画像を追加しようとしています
// Basic printing stuff
var printDialog = new PrintDialog();
var fixedDocument = new FixedDocument();
fixedDocument.DocumentPaginator.PageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
FixedPage page = new FixedPage();
page.Width = fixedDocument.DocumentPaginator.PageSize.Width;
page.Height = fixedDocument.DocumentPaginator.PageSize.Height;
Image img = new Image();
// PrintIt my project's name, Img folder
var uriImageSource = new Uri(@"/PrintIt;component/Img/Stuff.png", UriKind.RelativeOrAbsolute);
img.Source = new BitmapImage(uriImageSource);
img.Width = 100;
img.Height = 100;
page.Children.Add(img);
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(page);
fixedDocument.Pages.Add(pageContent);
// Print me an image please!
_printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Print");
それは私に白紙を与えます。他のUIElement(TextBox、Grid、Rectなど)は問題なく表示されるので、なぜだろうと思います。私は何が欠けていますか?
ありがとう!
PS OK、別の解決策を見つけました。理由はわかりませんが、そのウリで画像が正しく読み込まれます
var uri = new Uri("pack://application:,,,/Img/Stuff.png");