【发布时间】:2017-10-06 02:46:05
【问题描述】:
Skia 是一个图形库 (skia.org)。 该文档解释了如何在通过 git 克隆项目后 build 库。但截至目前,文档尚不清楚,如何使用使用 Skia 库的 Xcode 构建 C++ 项目。
我尝试了文档中的所有内容,但找不到如何在 C++ Xcode 项目中链接skia 库的方法。
【问题讨论】:
标签: c++ xcode macos build skia
Skia 是一个图形库 (skia.org)。 该文档解释了如何在通过 git 克隆项目后 build 库。但截至目前,文档尚不清楚,如何使用使用 Skia 库的 Xcode 构建 C++ 项目。
我尝试了文档中的所有内容,但找不到如何在 C++ Xcode 项目中链接skia 库的方法。
【问题讨论】:
标签: c++ xcode macos build skia
此屏幕截图显示了如何以及在何处执行这些步骤:
libskia.a 库文件的路径。 (注:我使用静态构建选项创建静态库。如果要链接动态.so库,设置略有不同)以下步骤应在与之前步骤相同的主窗口分区内执行。
-lskia 以静态链接libskia.a 库。以下步骤应在与之前步骤相同的主窗口分区内执行。
以下步骤应在与之前的步骤相同的主窗口分区内执行。 此屏幕截图显示了执行这些步骤的位置:
Add Skia Mac OSX Specific Dependencies Image
+ 符号。您可以使用以下示例代码测试这些设置:
#include "SkSurface.h"
#include "SkPath.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkStream.h"
int main (int argc, char * const argv[]) {
// hard coded example program parameters
const char filePath[] = "/Users/[yourUserName]/Desktop/skiaTestImage.png";
int width = 256;
int height = 256;
// create canvas to draw on
sk_sp<SkSurface> rasterSurface = SkSurface::MakeRasterN32Premul(width, height);
SkCanvas* canvas = rasterSurface->getCanvas();
// creating a path to be drawn
SkPath path;
path.moveTo(10.0f, 10.0f);
path.lineTo(100.0f, 0.0f);
path.lineTo(100.0f, 100.0f);
path.lineTo(0.0f, 100.0f);
path.lineTo(50.0f, 50.0f);
path.close();
// creating a paint to draw with
SkPaint p;
p.setAntiAlias(true);
// clear out which may be was drawn before and draw the path
canvas->clear(SK_ColorWHITE);
canvas->drawPath(path, p);
// make a PNG encoded image using the canvas
sk_sp<SkImage> img(rasterSurface->makeImageSnapshot());
if (!img) { return 1; }
sk_sp<SkData> png(img->encodeToData());
if (!png) { return 1; }
// write the data to the file specified by filePath
SkFILEWStream out(filePath);
(void)out.write(png->data(), png->size());
return 0;
}
您可以通过编写 make 文件或直接在终端中调用 g++ 编译器来完成相同的操作。这是一个例子:
g++ -std=c++11 main.cpp -framework CoreFoundation -framework \
CoreGraphics -framework CoreText -framework CoreServices - \
L[path_to_your_Skia_library]/skia/out/Static_m58 -lskia - \
I[path_to_your_Skia_library]/skia/include/core -\
I[path_to_your_Skia_library]/skia/include/config -\
I[path_to_your_Skia_library]/skia/include/utils -\
I[path_to_your_Skia_library]/skia/third_party/externals/sdl/include -\
I[path_to_your_Skia_library]/skia/include/gpu -\
I[path_to_your_Skia_library]/skia/src/gpu -o main
找出所有这些东西花了我大约 12 个小时。如果您对最终导致解决方案的步骤感兴趣,我将在此处进行解释。请告诉我。
【讨论】: