Changes the resolution of an existing Windows Enhanced Metafile (EMF).
emfHandle
Handle to the source EMF
xResolution
New horizontal resolution
yResolution
New vertical resolution
A handle to the modified Windows Enhanced Metafile (EMF).
This method is especially helpful in case you use the CreateEnhMetaFile Windows API when generating the EMF handle. For example, requirement is to create an EMF with 8.5 by 11 inches at 300 DPI. With CreateEnhMetaFile, the resolution of the generated EMF is the same as the resolution of the reference HDC. Since it is impractical to find an HDC with resolution equal to the desired one, you can use UpdateMetaFileResolution to accomplish this. Here is an example:
const int resolution = 300;
// Calculate the width in pixels:
int widthInPixels = (int)(8.5 * resolution);
int heightInPixels = (int)(11.0 * resolution);
Win32.RECT rc = new Win32.RECT();
rc.left = 0;
rc.top = 0;
rc.right = widthInPixels;
rc.bottom = heightInPixels;
IntPtr hdc = Win32.CreateEnhMetaFile(IntPtr.Zero, IntPtr.Zero, rc, IntPtr.Zero);
IntPtr hEmfTemp = Win32.CloseEnhMetaFile(hdc);
// hEmfTemp has the same resolution as the screen, change it to the desired one
IntPtr hEmf;
hEmf = DocumentWriter.UpdateMetaFileResolution(hEmfTemp, resolution, resolution);
Win32.DeleteEnhMetaFile(hEmfTemp);
// hEmf now is 8.5 by 11 at 300
If xResolution or yResolution is 0, then the original resolution of the EMF handle will be used. If either xResolution or yResolution is equal to -1, then the aspect ratio for original EMF handle will be maintained and the positive value for either xResolution or yResolution will be used as the resolution (DPI) value for the modified emf handle.
Note that xResolution and yResolution cannot be both less than zero.
This example will load an Enhanced Metafile from disk and then change its resolution to 200 by 200 dots per inch.