首页 > 解决方案 > 使用 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 时浏览到。

  1. FontFamily fontFamily(L"Times New Roman");

“无法使用‘wchar_t const [16]’类型的左值初始化‘FontFamily’类型的局部变量‘fontFamily’

  1. GraphicsPath path;

“类“GraphicsPath”不存在默认构造函数”

  1. path.AddString(...)

“类‘GraphicsPath’没有成员‘AddString’”

非常感谢任何帮助。我花了几个小时来解决这个问题,但进展为零。

标签: c++gdi+visual-studio-2019cinder

解决方案


经过高低搜索后,我想通了。我错过了几个包括。但老实说,我还是不太明白,为什么编译器会抱怨那个特定的消息......

以下为我编译并生成字母“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;
  }
}

推荐阅读