Metafile::EmfToWmfBits的使用
其中涉及到string转换LPCWSTR以及模块绝对路径的调用
#include <iostream> #include <stdio.h> #include <WINDOWS.H> #include <shellapi.h> #include <gdiplus.h> #include <Shlwapi.h> #include <string> #pragma comment (lib,"Shlwapi.lib") #pragma comment(lib,"gdiplus.lib") #pragma comment(lib, "shell32.lib") using namespace Gdiplus; using std::string; LPWSTR ConvertToLPWSTR(const std::string& s) { LPWSTR ws = new wchar_t[s.size() + 1]; // +1 for zero at the end copy(s.begin(), s.end(), ws); ws[s.size()] = 0; // zero at the end return ws; } int main(int argc, char **argv) { UINT size1 = 0; WCHAR path[MAX_PATH]; string name; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); std::cout << "Please input a file name" << std::endl; std::cin >> name; LPCWSTR name_ = LPCWSTR(ConvertToLPWSTR(name)); GetModuleFileNameW(NULL, path, MAX_PATH); PathRemoveFileSpecW(path); PathAppendW(path, name_); Metafile myMetafile(path); Status S_ch = myMetafile.GetLastStatus(); HENHMETAFILE hEmf = myMetafile.GetHENHMETAFILE(); size1 = Metafile::EmfToWmfBits( hEmf, 0, NULL, MM_ANISOTROPIC, EmfToWmfBitsFlagsEmbedEmf); std::cout << size1 << std::endl; }

浙公网安备 33010602011771号