将固定页面内容渲染到位图上
我有以下代码取自 http://www.codeplex.com/XPS2Image/ ,其中依次摘自 Microsoft 开发人员网络论坛上的讨论。
int[] pages = new int[] { 0, 1, 2, 3, 4 };
XpsDocument xpsDoc = new XpsDocument(@"c:\tmp\sample.xps", System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
// You can get the total page count from docSeq.PageCount
foreach (int pageNum in pages)
{
DocumentPaginator paginator = docSeq.DocumentPaginator;
DocumentPage docPage = paginator.GetPage(pageNum);
BitmapImage bitmap = new BitmapImage();
RenderTargetBitmap renderTarget =
new RenderTargetBitmap((int)docPage.Size.Width,
(int)docPage.Size.Height,
96, // WPF (Avalon) units are 96dpi based
96,
System.Windows.Media.PixelFormats.Pbgra32);
renderTarget.Render(docPage.Visual);
PngBitmapEncoder encoder = new PngBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
FileStream pageOutStream = new FileStream("c:\\tmp\\xpsdocPage" + pageNum + ".jpg", FileMode.Create, FileAccess.Write);
encoder.Save(pageOutStream);
pageOutStream.Close();
}
这工作正常,只是 FixedPage
中使用的远程 ResourceDictionaries
未呈现。 有任何想法吗?
I have the following code taken from http://www.codeplex.com/XPS2Image/, which in turn was taken from a discussion on the Microsoft Developer's Network forums.
int[] pages = new int[] { 0, 1, 2, 3, 4 };
XpsDocument xpsDoc = new XpsDocument(@"c:\tmp\sample.xps", System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
// You can get the total page count from docSeq.PageCount
foreach (int pageNum in pages)
{
DocumentPaginator paginator = docSeq.DocumentPaginator;
DocumentPage docPage = paginator.GetPage(pageNum);
BitmapImage bitmap = new BitmapImage();
RenderTargetBitmap renderTarget =
new RenderTargetBitmap((int)docPage.Size.Width,
(int)docPage.Size.Height,
96, // WPF (Avalon) units are 96dpi based
96,
System.Windows.Media.PixelFormats.Pbgra32);
renderTarget.Render(docPage.Visual);
PngBitmapEncoder encoder = new PngBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
FileStream pageOutStream = new FileStream("c:\\tmp\\xpsdocPage" + pageNum + ".jpg", FileMode.Create, FileAccess.Write);
encoder.Save(pageOutStream);
pageOutStream.Close();
}
This works fine, except that remote ResourceDictionaries
used in the FixedPage
are not rendered. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论