Skia is a graphics library (skia.org). The documentation explains how to build the library after cloning the project via git. But the documentation is unclear as of this date, h
This screenshot shows how and where to do these steps:
Add Skia Library Path Image
libskia.a
library file which you built earlier. (Note: I used the static build option to create a static library. If you want to link a dynamic .so
library, the settings are slightly different)The following steps should be performed inside the same main window division as the steps before.
-lskia
to statically link the libskia.a
library when building the project.The following steps should be performed inside the same main window division as the steps before.
The following steps should be performed inside the same main window division as the steps before. This screenshot shows where to do these steps:
Add Skia Mac OSX Specific Dependencies Image
+
sign.You may test these settings with the following example code:
#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 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 img(rasterSurface->makeImageSnapshot());
if (!img) { return 1; }
sk_sp 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;
}
You may accomplish the same by writing a make file or by invoking the g++ compiler directly in the terminal. Here is an example:
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
Finding all this stuff out took me around 12 hours. If you are interested in the steps which finally lead to the solution, I'll explain them here. Just let me know.