Reliable .wmf/wmf to Pixel based image conversion

百般思念 提交于 2019-12-24 20:50:30

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/785837/reliable-wmf-wmf-to-pixel-based-image-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!