can you give a bare minimum example of skia in c++
- User
can you give a bare minimum example of skia in c++
Assistant
Here's a minimal Skia C++ example that creates a simple drawing:
#include "include/core/SkCanvas.h" #include "include/core/SkSurface.h" #include "include/core/SkPaint.h" #include "include/encode/SkPngEncoder.h" #include "include/core/SkStream.h" int main() { // Create a surface (100x100 pixels) auto surface = SkSurface::MakeRasterN32Premul(100, 100); SkCanvas* canvas = surface->getCanvas(); // Clear background to white canvas->clear(SK_ColorWHITE); // Set up paint SkPaint paint; paint.setColor(SK_ColorRED); // Draw a circle canvas->drawCircle(50, 50, 30, paint); // Save to PNG auto image = surface->makeImageSnapshot(); auto data = SkPngEncoder::Encode(nullptr, image.get(), {}); SkFILEWStream stream("output.png"); stream.write(data->data(), data->size()); return 0; }To compile this, you'll need to:
- Build Skia or get prebuilt binaries
- Link against Skia libraries
- Include Skia headers in your include path
A typical compile command might look like:
g++ -std=c++17 main.cpp -I/path/to/skia -L/path/to/skia/out/Release -lskiaThis example creates a 100x100 pixel surface, draws a red circle, and saves it as a PNG file.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.