可靠的 .wmf/wmf 到基于像素的图像转换

发布于 2024-07-18 08:34:16 字数 313 浏览 12 评论 0原文

下午好,

我在 .net 内部(System.Drawing)基于元文件/图像处理包含透明区域的 .wmf 文件时遇到了一些麻烦。 基本上,每当我执行 MetaFile.LoadFile(...) 并将其保存为 tiff/png 等时,源文件的某些区域都会丢失。 我无法真正确定它,但似乎图元文件中基于矢量的信息工作正常,但基于像素的区域(例如放置在 .wmf 中的图像)丢失了。

有谁知道一种可靠的.net本机和非第三方方法来正确转换wmf文件(例如..最终基于像素的图像看起来像..wmf..只是..好吧..像素化)?

干杯和感谢, -J

Good afternoon,

I am having a little trouble with .net's internal (System.Drawing) based MetaFile / Image handling of .wmf files that containt transparent areas. Basically whenever I do a MetaFile.LoadFile(...) and take that to save it as a tiff/png etc, some areas of that source files are missing. I can't really pin it down, but it -seems- like the vector based informations within the metafile just work fine, but the pixel-based areas (e.g. an image placed within the .wmf) are missing.

Does anyone know a reliable, .net native and non 3rd-party way to convert wmf files properly (as in.. the final pixel based image looks like the .wmf.. just.. well.. pixelated)?

Cheers and thanks,
-J

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吾家有女初长成 2024-07-25 08:34:16

问题在于.NET是GDI+,而WMF/EMF是GDI。 重要的是要知道 GDI+ 与 GDI 不兼容,它们具有完全不同的 API 和功能。 因此,GDI 图元文件中的某些操作的行为不符合预期。 透明位图以及图元文件等的世界变换通常并不像微软所宣传的那样有效。

到目前为止,我得到的最好的结果是将图元文件转换为本机 GDI+,这需要模拟 GDI 堆栈并应用一些主要调整以使文本定位等正确。

看看 EMFExplorer,那里找到的信息会有很大帮助。
http://www.codeproject.com/KB/GDI-plus/emfexplorer。 ASPX

The problem is that .NET is GDI+, while WMF/EMF is GDI. It's important to know that GDI+ is not compatible with GDI, they have completely different APIs and capabilities. Therefore, some operations in GDI metafiles behave not as expected. Transparent bitmaps, but also world transformations on metafiles etc. do often not really work as advertized by Microsoft.

The best I have gotten so far is to convert the metafile to native GDI+, which requires emulating the GDI stack and applying some major tweaks to get text positioning etc. right.

Have a look at EMFExplorer, the information found there could help a lot.
http://www.codeproject.com/KB/GDI-plus/emfexplorer.aspx

浪漫之都 2024-07-25 08:34:16

好的,显然,将图元文件(.wmf/.emf)转换为另一种格式的最可靠方法是使用 .png 作为输出格式,因为 msdn 描述图元文件中的某处无论如何都会在内部处理/转换为 png 格式(使用 alpha 等) ),例如 Metafile.Save("somewhere"...) 默认情况下将以 png ImageFormat 输出。

因此,如果您确实想从图元文件输入中创建非 png 图像,如果您加倍努力,进行变换和转换,您将获得最佳结果。 将其存储为 png,然后将该 png 重新转换为最终格式。 有点蹩脚,但话又说回来……无论如何,wmf 本身很奇怪,我得出(我个人的)结论,它是邪恶的。 ;)

-J

Ok, well the apparently most reliably way to transform metafiles (.wmf/.emf) into another format is to use .png as output format, as somewhere in the msdn description metafiles are internally handled/transformed into png format anyway (with alpha etc) and e.g. a Metafile.Save("somewher"...) by default would output in png ImageFormat.

So in case you do want to create a non-png image out of a Metafile input, you get the best result if you go the extra mile, transform & store it as a png, and take that png and re-transform it to your final format. Kinda lame, but then again.. wmf itself is weird anyway and I've come to the (my personal) conclusion it's evil. ;)

-J

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文