gpt4 book ai didi

WPF 图像矢量格式导出(XPS?)

转载 作者:行者123 更新时间:2023-12-04 19:18:32 28 4
gpt4 key购买 nike

我们的工具允许导出为 PNG,效果非常好。
现在,我想将导出添加到某种矢量格式。我尝试了 XPS,但结果根本不令人满意。

看看对比http://www.jakubmaly.cz/xps-vs-png.png .
左边的图片来自 XPS 导出,右边的图片来自 PNG 导出,在 XPS 查看器中打开并放大 100% 时,XPS 图片明显模糊。

是否有任何我遗漏的设置或为什么会这样?

谢谢,
雅库布。

可以在此处找到示例 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;

最佳答案

有趣(且烦人)的问题 - 您可能想查看从 Jo0815 到 Printing XpsDocument causes resampled images (96dpi?) - FixedDocument prints sharp 的冗长答案。 ,引用 Microsoft 支持响应 - 几个摘录:

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.

[...]

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 显示器?

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

Additionally the problem only occurs when printing XPS and isn't a problem when printing XAML directly. I'm pretty sure there is documentation somewhere that says XPS will print at device resolution. [...] It is something we plan to improve in the next version of the product but not for Win 7. The problem is that when printing XAML it will correctly render the image at 600dpi, but when printing XPS it will still render the image at 96dpi. Since XAML is converted to XPS before printing it seems highly odd that one method of printing XPS produces different results to another method of printing XPS. [emphasis mine]

[...]

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.



结论

总之,我还是会尝试调整 PrintTicket.PageResolution PropertyNéstor Sánchez' approach (+1),如果您的用例确实允许这样做(尽管我远程记得在某处阅读过,这也没有任何影响); Using the XPS Rasterization Service中的位图分辨率和像素格式部分确认他在使用 FixedDocument 时遇到的问题:

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 对相关问题的解决方案 How to convert a XPS file to an image in high quality (rather than blurry low resolution)? ,建议使用 xps2img , 一个 XPS (XML Paper Specification) 文件到一组图像转换实用程序。特别是它允许指定图像大小或 DPI,这可能会有所帮助,具体取决于依次应用的打印路径解决方案。

祝你好运!

关于WPF 图像矢量格式导出(XPS?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490576/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com