【发布时间】:2011-09-23 08:25:45
【问题描述】:
我们的工具允许导出为 PNG,效果非常好。 现在,我想将导出添加到一些矢量格式。我试过XPS,但结果一点也不令人满意。
看看比较http://www.jakubmaly.cz/xps-vs-png.png。 左边的图片来自 XPS 导出,右边的图片来自 PNG 导出,XPS 图片在 XPS Viewer 中打开并放大 100% 时明显模糊。
我是否缺少任何设置或为什么会这样?
谢谢, 雅库布。
可以在此处找到示例 xps 输出:http://www.jakubmaly.cz/files/a.xps。 这是执行 XPS 导出的代码:
if (!boundingRectangle.HasValue)
{
boundingRectangle = new Rect(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight);
}
// Save current canvas transorm
Transform transform = frameworkElement.LayoutTransform;
// Temporarily reset the layout transform before saving
frameworkElement.LayoutTransform = null;
// Get the size of the canvas
Size size = new Size(boundingRectangle.Value.Width, boundingRectangle.Value.Height);
// Measure and arrange elements
frameworkElement.Measure(size);
frameworkElement.Arrange(new Rect(size));
// Open new package
System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(filename, FileMode.Create);
// Create new xps document based on the package opened
XpsDocument doc = new XpsDocument(package);
// Create an instance of XpsDocumentWriter for the document
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
// Write the canvas (as Visual) to the document
writer.Write(frameworkElement);
// Close document
doc.Close();
// Close package
package.Close();
// Restore previously saved layout
frameworkElement.LayoutTransform = transform;
【问题讨论】:
-
您可能错过了某处的设置 - XPS 非常有能力产生清晰的输出。您能否在某处发布实际导出的 xps,并提供有关您如何导出以及您使用的 XPS 查看器的更多信息?
-
我添加了生成 XPS 的实际代码以及指向结果的链接。我正在使用 Windows 7 内置的 XPS 查看器。我的目标是得到一个漂亮而清晰的矢量PDF,如果有其他方法,请给我提示。