SkiaSharp.SKSurface Class

Represents the backend/results of drawing to a canvas.

See Also: SKSurface

Syntax

public class SKSurface : SKObject

Remarks

The surface represents the backend/results of drawing to a canvas. For raster drawing, the surface will be pixels, but (for example) when drawing into a PDF or SKPicture canvas, the surface stores the recorded commands.

The surface always has non-zero dimensions. If there is a request for a new surface, and either of the requested dimensions are zero, then null will be returned.

Once you create a surface with one of its SKSurface.Create methods, you can draw into the canvas returned by the SKSurface.Canvas property. Once the drawing is complete, you can retrieve an SKImage by calling the SKSurface.Snapshot method.

C# Example

using (var surface = SKSurface.Create (width: 640, height: 480, SKImageInfo.PlatformColorType, SKAlphaType.Premul)) {
    // fetch the canvas where we draw into
    SKCanvas myCanvas = surface.Canvas;

    // Configure our brush
    var redBrush = new SKPaint () {
        Color = new SKColor (0xff, 0, 0),
	IsStroke = true
    };
    var blueBrush = new SKPaint () {
        Color = new SKColor (0, 0, 0xff),
	IsStroke = true
    };

    for (int i = 0; i < 64; i += 8)
        canvas.DrawRect (new SKRect (i, i, 256-i, 256-i), (i % 16 == 0) ? redBrush : blueBrush);

    // Save the artwork
    var pngEncodedFile = surface.Snapshot().Encode();
    File.WriteAllBytes ("demo.png", pngEncodedFile);
}

Requirements

Namespace: SkiaSharp
Assembly: SkiaSharp (in SkiaSharp.dll)
Assembly Versions: 1.0.0.0, 1.49.0.0, 1.52.0.0, 1.53.0.0, 1.54.0.0, 1.54.0.0, 1.55.0.0, 1.56.0.0, 1.57.0.0, 1.58.0.0, 1.59.0.0

The members of SkiaSharp.SKSurface are listed below.

See Also: SKObject

Public Properties

[read-only]
CanvasSKCanvas. Gets the canvas for this surface which can be used for drawing into it.
[read-only]
SurfacePropsSKSurfaceProps. Gets the surface property configuration.

Public Methods

static
Create(SKImageInfo) : SKSurface
Creates a new surface with the specified image parameters.
static
Create(SKPixmap) : SKSurface
Creates a new surface with the specified pixmap.
static
Create(GRContext, GRBackendRenderTargetDesc) : SKSurface
Wraps a pre-existing 3D API rendering target as a surface.
static
Create(GRContext, GRBackendTextureDesc) : SKSurface
Wraps a pre-existing 3D API texture as a surface.
static
Create(SKImageInfo, SKSurfaceProps) : SKSurface
Creates a new surface from the specified image parameters and surface properties.
static
Create(SKPixmap, SKSurfaceProps) : SKSurface
Creates a new surface with the specified pixmap and surface properties.
static
Create(GRContext, GRBackendRenderTargetDesc, SKSurfaceProps) : SKSurface
Wraps a pre-existing 3D API rendering target as a surface.
static
Create(GRContext, GRBackendTextureDesc, SKSurfaceProps) : SKSurface
Wraps a pre-existing 3D API texture as a surface.
static
Create(GRContext, Boolean, SKImageInfo) : SKSurface
Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.
static
Create(SKImageInfo, IntPtr, Int32) : SKSurface
Creates a new surface with the specified image parameters using a provided buffer.
static
Create(GRContext, Boolean, SKImageInfo, Int32) : SKSurface
Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.
static
Create(SKImageInfo, IntPtr, Int32, SKSurfaceProps) : SKSurface
Creates a new surface from the specified image parameters, the provided buffer and surface properties.
static
Create(Int32, Int32, SKColorType, SKAlphaType) : SKSurface
Creates a new surface with the specified image parameters.
static
Create(GRContext, Boolean, SKImageInfo, Int32, SKSurfaceProps) : SKSurface
Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.
static
Create(Int32, Int32, SKColorType, SKAlphaType, SKSurfaceProps) : SKSurface
Creates a new surface with the specified image parameters and surface properties.
static
Create(Int32, Int32, SKColorType, SKAlphaType, IntPtr, Int32) : SKSurface
Creates a new surface with the specified image parameters using a provided buffer.
static
Create(Int32, Int32, SKColorType, SKAlphaType, IntPtr, Int32, SKSurfaceProps) : SKSurface
Creates a new surface with the specified image parameters using a provided buffer and surface properties.
static
CreateAsRenderTarget(GRContext, GRBackendTextureDesc) : SKSurface
Wraps a pre-existing backend 3D API texture as a surface.
static
CreateAsRenderTarget(GRContext, GRBackendTextureDesc, SKSurfaceProps) : SKSurface
Wraps a pre-existing backend 3D API texture as a surface.
Draw(SKCanvas, Single, Single, SKPaint)
Draws the current surface on the specified canvas.
PeekPixels() : SKPixmap
Returns the pixels, if they are available.
PeekPixels(SKPixmap) : Boolean
Returns the pixmap of the surface.
ReadPixels(SKImageInfo, IntPtr, Int32, Int32, Int32) : Boolean
Copies the pixels from the surface into the specified buffer.
Snapshot() : SKImage
Takes a snapshot of the surface and returns it as an image.

Protected Methods

override
Dispose(Boolean)