0

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.

Oliver Bock
  • 4,829
  • 5
  • 38
  • 62

2 Answers2

1

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

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • Yes, but how do I create a much higher resolution memory DC? Can you point at any documentation? – Oliver Bock Feb 09 '11 at 06:33
  • I can use CreateCompatibleBitmap() to create a bitmap with very many pixels, but it will have the same DPI as the screen, and thus my metafile will get drawn in the upper-left corner, with the same problems as before. Perhaps if I exagerate the size of the drawing area when creating the original Enhanced Metafile then I can get it to use more of the bitmap while doing the conversion. Is this what you mean? How are fonts screwed up by this process? – Oliver Bock Feb 10 '11 at 04:10
  • CreateEnhMetafile is the appropriate API for this – David Heffernan Feb 10 '11 at 20:09
0

Ask Google for ENMETA.EXE

Description by Microsoft

Example in download included.

  • Ah, you will use it for Your SPPS clone. – Coconut Feb 11 '11 at 08:08
  • 1
    Coiche placeable metafiles for best results. Sometime it's useful to add 0.1 mm on the right side and the bottom. Some programs cut these by inserting the wmf graphic. – Coconut Feb 11 '11 at 08:15
  • ENMETA's code that converts enhanced metafiles to Windows metafiles uses the screen DC (GetDC(NULL)) and thus will suffer from the problem I originally described. Yes, it's for Q, which *is* a competitor to SPSS, but hardly a clone. Perhaps you want PSPP? – Oliver Bock Feb 13 '11 at 22:13