使用CreateMetaFile创建WMF文件,并转换为EMF文件

#include <iostream>
#include <stdio.h>
#include <WINDOWS.H>
#include <shellapi.h>
#include <gdiplus.h>
#include <Shlwapi.h>


#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(0, 0, 255));

    Rectangle(hdcMeta, 0, 0, 100, 100);

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

    SelectObject(hdcMeta, hBrush);
    Ellipse(hdcMeta, 20, 20, 80, 80);
    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 0; }
GetMetaFileBitsEx需要调用两次,第二次调用是为了填充buffer缓冲区

原文链接: https://www.cnblogs.com/strive-sun/p/11836215.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    使用CreateMetaFile创建WMF文件,并转换为EMF文件

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/405059

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月25日 下午4:52
下一篇 2023年4月25日 下午4:52

相关推荐