WPF图像矢量格式导出(XPS?) [英] WPF image vector format export (XPS?)

查看:257
本文介绍了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.

查看比较 http://www.jakubmaly.cz/xps-vs-png.png
左边的图片来自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输出示例: http://www.jakubmaly.cz/files/a.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 打印XpsDocument会导致重新采样的图像(96dpi?) - FixedDocument打印锐利,引用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:


我们的GDI代码中不能模拟WPF的一些矢量特征,而
我们将将场景的子集转换为GDI位图。这些
位图是模糊缩放的原因。

Some vector features from WPF cannot be emulated in our GDI code and we resort to converting subsets of the scene to GDI bitmaps. These bitmaps are the cause of the blurred zooming.

[...]

这些位图是模糊缩放的原因。问题是
,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时,直接打印XAML时不是
问题。我确定在
文档的某个地方说,XPS将在设备解析时打印。
[...] 我们的
计划在下一个版本的产品中改进,但不适用于Win 7。

问题是当打印时XAML它将正确地渲染
图像为600dpi,但是当打印XPS时,它仍然会以96dpi的形式呈现图像
由于XAML在打印之前被转换为XPS,所以似乎
非常奇怪,一种打印XPS的方法对另一种打印XPS的方法产生不同的结果

[...]

没有配置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.



结论



总之,我仍然尝试调整NéstorSánchez中的print / '方法(+1),如果你的用例确实允许这个(虽然我远程回忆一下,这也没有任何效果); rel =nofollow noreferrer>使用XPS光栅化服务证实了他使用 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:


固定页面的XPS光栅化对象必须知道页面将被呈现的
的分辨率。 XPSDrv过滤器以每英寸点数(DPI)的形式将此
分辨率指定为输入参数[...]例如,如果显示设备的分辨率为
为600 DPI,则固定页面描述一个标准的信纸页面,整个页面的
位图图像具有以下维度[...]

XPS rasterizer object for a fixed page must know the resolution at which the page will be rendered. The XPSDrv filter specifies this resolution, in dots per inch (DPI), as an input parameter [...] For example, if a display device has a resolution of 600 DPI, and a fixed page describes a standard letter-size page, a bitmap image of the entire page has the following dimensions [...]



解决方法



作为潜在的解决方法,您可能需要探索alexandrud的相关问题解决方案如何将XPS文件转换为高质量的图像(而不是模糊的低分辨率)?,建议使用 xps2img ,一个用于设置图像转换实用程序的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?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆