【发布时间】:2015-09-10 17:05:22
【问题描述】:
我正在使用XpsDocument 类即时生成XPS 文件。在我的XAML 模板中,我将JPEG 图像嵌入到Image 容器中。 但是,生成的 XPS 中的嵌入图像始终为 PNG 图像 - 导致某些类型的图像文件非常大。
文档编写者似乎将渲染的图像解释为位图,然后将它们保存为PNG。
这是产生XPS的代码:
void ConvertToXps(IEnumerable<FixedDocument> fixedDocuments, Stream outputStream)
{
var package = Package.Open(outputStream, FileMode.Create);
var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
var xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
// XPS documents are built using fixed document sequences.
var fixedDocSeq = new FixedDocumentSequence();
// A4 = 210 x 297 mm = 8.267 x 11.692 inches = 793.632 * 1122.432 dots
fixedDocSeq.DocumentPaginator.PageSize = new Size(793.632, 1122.432);
foreach (var fixedDocument in fixedDocuments)
{
var docRef = new DocumentReference();
docRef.BeginInit();
docRef.SetDocument(fixedDocument);
docRef.EndInit();
((IAddChild)fixedDocSeq).AddChild(docRef);
}
// Write out our fixed document to XPS.
xpsWriter.Write(fixedDocSeq.DocumentPaginator);
xpsDoc.Close();
package.Close();
}
问:如何在生成的XPS 中强制将我的XAML 渲染图像保存为JPEG?
【问题讨论】: