Proper way to convert an Enhanced Metafile to a Windows Metafile without pixel rounding

1.1k views Asked by At

When I convert an Enhanced Metafile (constructed via GDI+ in C#) into an old-style Windows Metafile, the results are very rough, apparently because coordinates are being rounded to the nearest screen pixel. I see this if I convert either via

GetWinMetaFileBits(emfh, bits_l, bits, MM_ANISOTROPIC, GetDC(0));

or using GDI+'s Metafile::EmfToWmfBits. The culprit is presumably the screen DC being used. This posting suggests using a printer DC, which works for me, but obviously will not work if the user has no printers installed. Is there a better way? I have considered creating a high-resolution in-memory DC for the purpose, but I can find no proper documentation for doing so, and I also worry about the RAM used.

2

There are 2 answers

3
Martin Beckett On

The normal way is to create a much higher resolution memory DC, render to that and then save it however you want. Note that font sizes can get screwed up by this.

 HDC memDC = CreateCompatibleDC ( hDC );
 HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight );
 SelectObject ( memDC, memBM );

With nWidth , nHeight much larger.
The CreateCompatible bit should set all the dpi etc, but I have had problems where the fonts were drawn fixed pixel size rather than rescaled - so they ended up being only 10pixels high on a 10,000 pixel image

3
Coconut On

Ask Google for ENMETA.EXE

Description by Microsoft

Example in download included.