Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

can you give a bare minimum example of skia in c++

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-small-2506’s answer.
  1. User

    can you give a bare minimum example of skia in c++

  2. Claude 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:

    1. Build Skia or get prebuilt binaries
    2. Link against Skia libraries
    3. 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 -lskia
    

    This example creates a 100x100 pixel surface, draws a red circle, and saves it as a PNG file.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.