我在c++程序中使用c++类,在“资源文件”文件夹中使用.ttf文件。我希望能够这样做:
privateFontCollection.AddFontFile(L"Exo-Regular.ttf");但是,我唯一能找到它的方法是通过本地文件路径访问它,如下所示:
privateFontCollection.AddFontFile(L"C:\\Users\\maybe\\Desktop\\Exo-Regular.ttf");发布于 2018-11-06 00:21:53
您不能用AddFontFile()方法来实现这一点;它所期望的路径字符串不能解析到嵌入在编译程序中的资源中。
相反,您必须使用AddMemoryFont()...and向它传递一个指针,指向通过资源感知API获取的资源数据。
2013年有个问题是有人在C#上这么做的:“来自资源的addFontFile”。我不知道您使用的是什么其他类库,但是如果您正在编写直接的Win32程序,那么获得一个指针和字体大小的结果如下所示:
HMODULE module = NULL; // search current process, override if needed
HRSRC resource = FindResource(module, L"Exo-Regular.ttf", RT_RCDATA);
if (!resource) {...error handling... }
HGLOBAL handle = LoadResource(module, resource);
if (!handle) {...error handling... }
// "It is not necessary to unlock resources because the system
// automatically deletes them when the process that created
// them terminates."
//
void *memory = LockResource(handle);
DWORD length = SizeofResource(module, resource);
privateFontCollection.AddMemoryFont(memory, length);https://stackoverflow.com/questions/53163955
复制相似问题