本文介绍了WPF图像矢量格式导出(XPS?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的工具允许出口到PNG,这个工作非常好。
现在,我想将导出添加到一些矢量格式。我尝试过XPS,但结果并不令人满意。

Our tool allows export to PNG, which works very nicely. Now, I would like to add export to some vector format. I tried XPS, but the results are not satisfying at all.

查看比较。
左边的图片来自XPS导出,从PNG导出右侧的图片,XPS图片在XPS Viewer中打开时被明显模糊,并且缩放100%。

Take a look at a comparison http://www.jakubmaly.cz/xps-vs-png.png. The picture on the left comes from an XPS export, the picture on the right from PNG export, the XPS picture is visibly blurred when opened in XPS Viewer and zoomed 100%.

有没有我缺少的设置,为什么会这样?

Are there any settings that I am missing or why is it so?

谢谢,
Jakub。

Thanks,Jakub.

可以在这里找到一个xps输出示例:。
这是XPS导出的代码:

A sample xps output can be found here: http://www.jakubmaly.cz/files/a.xps. This is the code that does the XPS export:

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;


推荐答案

有趣(烦人)的问题 - 你可能想请查看从 Jo0815 到,引用Microsoft支持响应 - 几个摘录:

Interesting (and annoying) issue - you may want to check out the lengthy answer from Jo0815 to Printing XpsDocument causes resampled images (96dpi?) - FixedDocument prints sharp, quoting a Microsoft support response - a couple of excerpts:

[...]

这些位图是模糊缩放的原因。问题是
,WPF正在被光栅化到位图 - 在分辨率。
打印路径旨在将不支持的功能栅格化为
位图,但它应该在设备解析时执行。相反,
光栅化始终在96dpi下完成。对于
的屏幕,但是对于600dpi打印机产生模糊输出

These bitmaps are the cause of the blurred zooming. The problem is that the WPF is being rasterised to a bitmap at the -wrong resolution. The print path is designed to rasterise unsupported features into a bitmap, but it is supposed to do it at device resolution. Instead the rasterisation is always being done at 96dpi. That's fine for a screen but produces blurred output for a 600dpi printer. [emphasis mine]

请注意,后者将适用于当今更高的DPI屏幕,我已经遇到过这样的不同时期的模糊 - 你有机会使用高DPI监视器吗?

Please note that the latter will apply for nowadays higher DPI screens as well of course, I've encountered blurring like this various times already - do you by chance use a high DPI monitor?

现在,显然微软并没有完全控制设备的这个:

Now, apparently Microsoft is not entirely in control of the apparatus regarding this:

[...]

没有配置XPS Document Writer DPI的UI 。如果你以后
打印一个生成的XPS文档在不同的DPI与作者
内部默认值,你可能会得到不好的结果为位图内容。使用GDI
打印机,您可以控制最终的DPI,并且您最终的沮丧是
通用纸 - 没有机会重印该文档。

There is no UI to configure the XPS Document Writer DPI. If you later print a generated XPS document at a different DPI from the writers internal default you may get poor results for bitmap content. With GDI printers you can control the final DPI and your final desitination is usally paper - no chance to reprint the document.



结论



总之,我仍然尝试调整(+1),如果你的用例确实允许这个(虽然我远程回忆一下,这也没有任何效果); 证实了他使用 FixedDocument 遇到的问题:

Conclusion

In conclusion, I'd still try to adjust PrintTicket.PageResolution Property within Néstor Sánchez' approach (+1), if your use case does allow this (though I remotely recall reading somewhere, that this doesn't have any effect as well); section Bitmap Resolution and Pixel Format in Using the XPS Rasterization Service confirms the issue he encountered with FixedDocument:



解决方法



作为潜在的解决方法,您可能需要探索alexandrud的相关问题解决方案,建议使用,一个用于设置图像转换实用程序的XPS(XML Paper Specification)文档。特别地,它允许指定图像大小或DPI ,这可能有助于依赖于打印路径解决方案。

Workaround

As a potential workaround you might want to explore alexandrud's solution for the related question How to convert a XPS file to an image in high quality (rather than blurry low resolution)?, which recommends using xps2img, a XPS (XML Paper Specification) document to set of images conversion utility. In particular it Allows to specify images size or DPI, which might help depending on the print path solution applied in turn.

祝你好运!

这篇关于WPF图像矢量格式导出(XPS?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:50