SkiaSharp Documentation

repository·main·Indexed 26 days ago

https://github.com/mono/skiasharp

A cross-platform 2D graphics API for .NET providing bindings for Google's Skia Graphics Library. It supports rendering high-performance 2D graphics across mobile, desktop, web, and server platforms, including .NET Standard 2.0, .NET 6+, Android, iOS, macOS, WinUI 3, and WebAssembly (WASM).

Tokens
125.6K
Snippets
283
Records
567
Agent score
89%

What's inside SkiaSharp

  1. Overview of SkiaSharp Transforms

    main

    SkiaSharp implements graphics transforms as methods of the SKCanvas object. These transforms alter the coordinates and sizes specified in SKCanvas drawing functions during rendering. They are useful for drawing repetitive graphics or creating animations.

    Affine Transforms

    Affine transforms preserve parallel lines and ensure coordinates/sizes do not become infinite. Supported operations include:

    • Translate: Shifts coordinates from one location to another.
    • Scale: Increases or decreases coordinates and sizes.
    • Rotate: Rotates coordinates around a specific point.
    • Skew: Shifts coordinates horizontally or vertically (e.g., turning a rectangle into a parallelogram).

    Non-Affine (Projective/Perspective) Transforms

    Based on a standard 3-by-3 transform matrix, non-affine transforms allow for more complex effects, such as transforming a square into a convex quadrilateral. These are essential for 3D effects but can cause coordinates or sizes to become infinite.

  2. Overview of SkiaSharp

    main
    SkiaSharp is a cross-platform 2D graphics API for .NET that provides C# bindings for Google's Skia Graphics Library. It operates through a layered architecture where the C# layer acts as a safety boundary for parameter validation and exception handling, communicating via P/Invoke to a minimal C API, which then interfaces with the underlying C++ Skia implementation.
  3. Overview of SkiaSharp Web Sample Features

    main

    The SkiaSharp Web Sample showcases the following capabilities for server-side rendering:

    • SKSurface: Used to create CPU-rendered surfaces server-side for individual API requests.
    • SKCanvas.DrawText: Used to render dynamic text into PNG images via a REST endpoint.
    • API Controller: Provides a GET /api/images/{text} endpoint that returns a SkiaSharp-rendered PNG containing the specified text.
    • Razor Pages: A Bootstrap-styled interface to display the generated images.
    • MapStaticAssets: Utilizes the latest ASP.NET Core static asset serving pipeline.
  4. Overview of SkiaSharp

    main

    SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API for rendering images across mobile, server, and desktop models.

    Supported platforms include:

    • .NET Standard 2.0, .NET Core, .NET 6+, and .NET Framework 4.6.2+ (4.8 recommended)
    • Android, iOS, tvOS, macOS, Mac Catalyst
    • Tizen
    • WinUI 3 (Windows App SDK / Uno Platform)
    • Windows Classic Desktop (Windows.Forms / WPF)
    • Web Assembly (WASM)
    • Uno Platform (iOS / Android / Windows / macOS / Linux / WebAssembly)
  5. Work with SkiaSharp bitmaps

    main

    SkiaSharp provides comprehensive support for raster graphics (bitmaps) in .NET applications. You can perform the following tasks with SkiaSharp bitmaps:

    • Displaying: Render bitmaps at native pixel sizes or scaled to fit rectangles while preserving aspect ratio.
    • Creating and Drawing: Generate new bitmaps and use them as drawing surfaces by creating a SKCanvas.
    • Cropping: Implement interactive cropping interfaces by defining cropping rectangles.
    • Specialized Rendering: Use nine-patch and lattice rendering options for segmented displays.
    • File I/O: Save bitmaps to files or system photo libraries.
    • Pixel Manipulation: Access and modify individual pixel bits directly.
    • Animation: Create animations by sequentially displaying bitmaps or rendering animated GIF files.
  6. Understand the 3-step Issue Pipeline workflow

    main

    The issue pipeline is designed to minimize duplicated work by separating investigation, reproduction, and fixing into three distinct stages. Data is passed between stages using JSON artifacts.

    StepSkillOutputPrimary job
    1issue-triageai-triage/{n}.jsonClassification, code investigation, workaround search, suggested action
    2issue-reproai-repro/{n}.jsonStandalone repro + version results (reporter → latest → main)
    3issue-fixai-fix/{n}.json + PRRoot-cause, minimal fix, regression test; consumes triage/repro artifacts
  7. Understand SkiaSharp bitmap memory layout

    main
    A SkiaSharp bitmap stored in memory is uncompressed and organized as a sequential series of pixels. The memory block starts with the first row of pixels (left to right) and continues through subsequent rows. For full-color bitmaps, each pixel consists of four bytes. The total memory required is calculated as 4 * width * height.
  8. Understand the relationship between API diffs and Release Notes

    main

    The API-diff engine (Cake) and the Release-notes prose engine (Python) are distinct but synchronized via two shared contracts:

    1. scripts/infra/docs/versions.json: The single source of truth for:

      • Supersession: Only versions explicitly marked with status: superseded are treated as superseded. Neither engine auto-detects this; you must add it to the JSON file.
      • compare_to baselines: When a version has a compare_to entry, both engines will diff against that specific baseline instead of the previous version.
    2. documentation/docfx/releases/_sources/co-release-map.json: A one-way hand-off from Cake to Python. The Cake engine writes {skia_line: harfbuzz_line} pairings here, which the Python engine reads to include HarfBuzzSharp API diff links within SkiaSharp pages.

    Note on Granularity: API diffs are designed to be fine-grained (one folder per emitted line, per assembly), whereas Release Notes are cumulative (one page per release). This difference in granularity is intentional.

  9. Explore SkiaSharp Gallery features

    main

    The SkiaSharp Gallery provides several interactive tools for testing graphics capabilities:

    • Interactive Demos: 21 demos covering gradients, transforms, shaders, text, paths, and image filters.
    • Rendering Toggles: Switch between CPU and GPU rendering (WebGL or software rasterizer).
    • SkSL Shader Playground: An editor for SkSL runtime effects with 5 animated presets.
    • 3D Transforms: Demonstrates 4×4 matrix pipelines using native SKMatrix44.
    • PDF Generation: Includes a PDF composer and embedded viewer.
    • Live Controls: Use sliders, pickers, and toggles to modify graphics parameters in real-time.
  10. Understand the SkiaSharp Three-Layer Architecture

    main

    SkiaSharp uses a three-layer design to bridge C# and the native Skia C++ library. This architecture ensures ABI stability and prevents C++ exceptions from crossing P/Invoke boundaries.

    1. C# Wrapper Layer: Provides idiomatic .NET patterns, safety, and validation.
    2. C API Layer: An ABI-stable layer that acts as a minimal wrapper around C++.
    3. C++ Skia Library: The core engine.

    Data flows from C# through P/Invoke to the C API, which then casts types to interact with the C++ Skia library.

  11. Understand SkiaSharp API Design Principles

    main

    SkiaSharp APIs are designed around four core principles to ensure a high-quality developer experience:

    1. ABI Stability: The library maintains a stable Application Binary Interface (ABI) across versions. This means that adding new members is allowed, but modifying existing signatures or removing public APIs is strictly forbidden to prevent breaking downstream applications at runtime.
    2. Consistency: APIs follow established patterns for naming and behavior.
    3. Safety: Parameters are validated at the C# layer to ensure predictable failures.
    4. Discoverability: APIs are structured to be easy to find and use.
  12. SkiaSharp Drawing Basics Overview

    main
    SkiaSharp provides a cross-platform 2D graphics API for .NET. Once the SkiaSharp NuGet package is added to your .NET MAUI application, you can use canvases and paint objects to render graphics. The library supports drawing primitive shapes, handling bitmaps, managing transparency, animating graphics, and integrating text with rendered images.