使用CreateMetaFile创建WMF文件,并转换为EMF文件
阅读原文时间:2023年07月13日阅读:1

#include
#include
#include
#include
#include
#include

#pragma comment (lib,"Shlwapi.lib")
#pragma comment(lib,"gdiplus.lib")
#pragma comment(lib, "shell32.lib")

using namespace Gdiplus;

int main(int argc, char **argv)
{
static HMETAFILE hmf;
static int cxClient, cyClient;
HBRUSH hBrush;
HDC hdcMeta;

METAFILEPICT mp;  
HDC hDC;  
BYTE\* buffer;  
GdiplusStartupInput gdiplusStartupInput;  
ULONG\_PTR gdiplusToken;  
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

hdcMeta = CreateMetaFile("12\_.WMF");  
hBrush = CreateSolidBrush(RGB(, , ));

Rectangle(hdcMeta, , , , );

MoveToEx(hdcMeta, , , NULL);  
LineTo(hdcMeta, , );  
MoveToEx(hdcMeta, , , NULL);  
LineTo(hdcMeta, , );

SelectObject(hdcMeta, hBrush);  
Ellipse(hdcMeta, , , , );  
hmf = CloseMetaFile(hdcMeta);  
UINT nSize = GetMetaFileBitsEx(hmf, 0, NULL);

buffer = (BYTE\*)malloc(nSize);int err\_1 = GetLastError();

UINT bytesCopy = GetMetaFileBitsEx(hmf, nSize, buffer);

HENHMETAFILE hEMF = SetWinMetaFileBits(nSize, buffer, NULL, NULL);

int err\_2 = GetLastError();

HENHMETAFILE newHEMF = CopyEnhMetaFile(hEMF, "new EMF.emf");

DeleteMetaFile(hmf);

GdiplusShutdown(gdiplusToken);  
return ;  

}

GetMetaFileBitsEx需要调用两次,第二次调用是为了填充buffer缓冲区

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章