问题
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