Metafile::EmfToWmfBits method (gdiplusheaders.h)
Converts an enhanced-format metafile to a Windows Metafile Format (WMF) metafile and stores the converted records in a specified buffer.
Syntax
UINT EmfToWmfBits(
[in] HENHMETAFILE hemf,
[in] UINT cbData16,
[out] LPBYTE pData16,
[in, optional] INT iMapMode,
[in, optional] INT eFlags
);
Parameters
[in] hemf
Type: HENHMETAFILE
Handle to the enhanced-format metafile that is to be converted.
[in] cbData16
Type: UINT
Unsigned integer that specifies the number of bytes in the buffer pointed to by the pData16 parameter.
[out] pData16
Type: LPBYTE
Pointer to a buffer that receives the converted records. If pData16 is NULL, Metafile::EmfToWmfBits returns the number of bytes required to store the converted metafile records.
[in, optional] iMapMode
Type: INT
Optional. Specifies the mapping mode to use in the converted metafile. For a list of possible mapping modes, see SetMapMode. The default value is MM_ANISOTROPIC.
[in, optional] eFlags
Type: EmfToWmfBitsFlags
Optional. Element of the EmfToWmfBitsFlags enumeration that specifies options for the conversion. The default value is EmfToWmfBitsFlagsDefault.
Return value
Type: UINT
If the method succeeds and the buffer pointer is NULL, the return value is the number of bytes required to store the converted records. If the method succeeds and the buffer pointer is a valid pointer, the return value is the size of the metafile data in bytes. If the method fails, the return value is zero.
Remarks
When you call Metafile::EmfToWmfBits to determine the size of the required buffer, you must pass the same value for eFlags that you pass later when you call Metafile::EmfToWmfBits to perform the conversion. Otherwise, the size returned by the first call to Metafile::EmfToWmfBits will be incorrect.
This method cannot convert metafiles of type EmfTypeEmfPlusOnly. If you use this method to convert a metafile of type EmfTypeEmfPlusDual, the Enhanced Metafile (EMF) records in that metafile are converted, but the EMF+ records are not converted.
This method converts an enhanced metafile into a WMF metafile so that its picture can be displayed in an application that recognizes the older format.
The Metafile::EmfToWmfBits method does not invalidate the enhanced metafile handle. Call the DeleteEnhMetaFile function to release the handle when it is no longer needed.
To create a scalable WMF metafile, specify MM_ANISOTROPIC as the iMapMode parameter.
Examples
The following example converts an enhanced-format metafile to a WMF metafile. The last parameter passed to Metafile::EmfToWmfBits specifies that the enhanced-format metafile is embedded as a comment in the converted metafile.
// Construct a Metafile object from an existing EMF disk file.
Metafile myMetafile(L"SourceMetafile.emf");
// Get a handle to the EMF metafile.
HENHMETAFILE hEmf = myMetafile.GetHENHMETAFILE();
// Determine the size of the buffer that will receive the converted records.
UINT size = Metafile::EmfToWmfBits(
hEmf,
0,
NULL,
MM_ANISOTROPIC,
EmfToWmfBitsFlagsEmbedEmf);
// Allocate a buffer to receive the converted records.
BYTE* buffer = new BYTE[size];
// Convert the EMF records to WMF records.
INT convertedSize = Metafile::EmfToWmfBits(
hEmf,
size,
buffer,
MM_ANISOTROPIC,
EmfToWmfBitsFlagsEmbedEmf);
// Get a handle to the converted metafile.
HMETAFILE hmf = SetMetaFileBitsEx(size, buffer);
// Write the WMF metafile to a disk file.
CopyMetaFile(hmf, TEXT("ConvertedMetafile.wmf"));
DeleteMetaFile(hmf);
DeleteEnhMetaFile(hEmf);
delete[] buffer;
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdiplusheaders.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |