c++ - 使用 GraphicsPath::AddString() 抱怨“类 'GraphicsPath' 没有成员 'AddString'”
问题描述
我正在尝试GraphicsPath::AddString()
在我的 libcinder 项目中使用 GDI+ 的方法。
这个想法是通过上述方法创建一个字母/字形的路径,然后将其传递给gl::draw()
box2d's b2FixtureDef
。目标是创建显示精确碰撞行为的下降字母。
但是,从docs.microsoft.com获取的以下示例向我抛出了几个错误。
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#include <Box2D/Box2D.h>
#include <gdiplus.h>
#pragma comment (lib, "gdiplus.lib")
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
using namespace std;
// ...
void MyApp::draw()
{
FontFamily fontFamily(L"Times New Roman");
GraphicsPath path;
// const WCHAR
// Status AddString(
// IN const WCHAR *string,
// IN INT length,
// IN const FontFamily *family,
// IN INT style,
// IN REAL emSize, // World units
// IN const PointF &origin,
// IN const StringFormat *format
//)
path.AddString(
L"Hello World",
-1, // NULL-terminated string
&FontFamily("Arial"),
FontStyleRegular,
48,
PointF(50.0f, 50.0f),
NULL);
}
我的代码有几个问题无法修复...我项目的目标平台版本是 8.1,平台工具集是Visual Studio 2015 (v140)
. 标题在那里,可以在按下 F12 时浏览到。
FontFamily fontFamily(L"Times New Roman");
“无法使用‘wchar_t const [16]’类型的左值初始化‘FontFamily’类型的局部变量‘fontFamily’
GraphicsPath path;
“类“GraphicsPath”不存在默认构造函数”
path.AddString(...)
“类‘GraphicsPath’没有成员‘AddString’”
非常感谢任何帮助。我花了几个小时来解决这个问题,但进展为零。
解决方案
经过高低搜索后,我想通了。我错过了几个包括。但老实说,我还是不太明白,为什么编译器会抱怨那个特定的消息......
以下为我编译并生成字母“A”的路径坐标。
// other includes
#include <windows.h>
#include <ObjIdl.h>
#include <minmax.h>
#include <gdiplus.h>
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
#pragma comment (lib, "Gdiplus.lib")
// ...
void MyApp::setup()
{
// ...
GraphicsPath p(FillModeAlternate);
FontFamily fontFamily(L"Arial");
if (p.AddString(L"A", -1, &fontFamily, FontStyleRegular, 48, PointF(0.0f, 0.0f), NULL) != Status::Ok)
{
std::cout << "Error while adding points" << std::endl;
}
PointF points[64];
if (p.GetPathPoints(points, sizeof(points)) != Status::Ok)
{
std::cout << "Error while getting points" << std::endl;
}
}
推荐阅读
- node.js - 类型错误回调不是 Nodejs 中的函数
- javascript - 如何在直接从应用程序中删除 mac electron 应用程序时清除用户数据?
- mysql - 在 MySQL 中存储基因表达数据
- mosquitto - 如何正确地将证书传递给 mosquitto_pub 和 mosquitto_sub 以便进行 TLS 通信?
- android - Android Studio 3.5 的更新或全新安装未在启动时崩溃 [操作系统:Windows10 Pro]
- windows - 当我在 XAMPP Localhost 中启动 Apache 时,如何制作自动浏览器或加载 localhost 页面
- r - R Shiny for 循环中的反应性内容问题
- sql - Snowflake SQL - 将 mmddyyyy 转换为 mmyyyy,然后按 mmyyyy 分组
- authentication - Autodesk-forge,2 腿身份验证 (OAuth):oauth
- azure - Azure AD - 添加自定义属性