다른 UIElements로 이미지를 인쇄하고 싶습니다. FixedPage 인스턴스가있어서 이미지를 추가하려고합니다.WPF의 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");
저에게 빈 종이가 있습니다. 다른 UIElements (TextBox, Grid, Rect와 같은)가 아무런 문제없이 나타나기 때문에 왜 그런지 궁금합니다. 내가 뭘 놓치고 있니?
감사합니다.
추신 : 다른 해결책을 찾았습니다. 왜 그런데 우리 사진이 제대로로드 될지 모르겠다.
var uri = new Uri("pack://application:,,,/Img/Stuff.png");
에 더 명확하게하세요! 고마워요. – Semuserable
참고 사항 :이 코드를 "큰"(= 많은 페이지) FixedDocument에서 실행하면 OutOfMemoryExceptions은 코드에 의해 throw되지 않습니다. 그들은 단순히 무시되고 이미지는 표시되지 않습니다. 문제는이 코드와 다릅니다. BitmapFrame bitImage = BitmapFrame.Create (new FileStream (fileName, FileMode.Open, FileAccess.Read), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); –