小智 6
此屏幕快照显示了如何以及在何处执行这些步骤:
libskia.a您先前构建的库文件的路径。(注意:我使用static build选项创建了一个静态库。如果要链接一个动态.so库,设置会略有不同)以下步骤应在与之前步骤相同的主窗口内执行。
-lskia以静态链接libskia.a库。以下步骤应在与之前步骤相同的主窗口内执行。
以下步骤应在与之前步骤相同的主窗口内执行。此屏幕快照显示了执行这些步骤的位置:
+符号。您可以使用以下示例代码测试这些设置:
#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;
}
Run Code Online (Sandbox Code Playgroud)
您可以通过编写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个小时。如果您对最终导致解决方案的步骤感兴趣,我将在这里解释。请让我知道。