Edit

Share via


SKSurface Class

Definition

Represents the backend/results of drawing to a canvas.

public class SKSurface : SkiaSharp.SKObject
Inheritance

Examples

var info = new SKImageInfo(256, 256);
using (var surface = SKSurface.Create(info)) {
    SKCanvas canvas = surface.Canvas;

    canvas.Clear(SKColors.White);

    // 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) {
        var rect = new SKRect(i, i, 256 - i - 1, 256 - i - 1);
        canvas.DrawRect(rect, (i % 16 == 0) ? redBrush : blueBrush);
    }
}

The example above produces the following:

SKSurface

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 <see langword="null" /> will be returned.

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

Properties

Name Description
Canvas

Gets the canvas for this surface which can be used for drawing into it.

Context

Gets the GPU recording context associated with this surface.

Handle

Gets or sets the handle to the underlying native object.

(Inherited from SKObject)
IgnorePublicDispose

Gets or sets a value indicating whether the call the public Dispose() should be no-op.

(Inherited from SKNativeObject)
IsDisposed

Gets or sets a value indicating whether the object has already been disposed.

(Inherited from SKNativeObject)
OwnsHandle

Gets or sets a value indicating whether this object owns its handle and should destroy the native object when it is disposed.

(Inherited from SKNativeObject)
SurfaceProperties

Gets the surface property configuration.

SurfaceProps
Obsolete.

Gets the surface property configuration.

Methods

Name Description
Create(GRContext, Boolean, SKImageInfo, Int32, GRSurfaceOrigin, SKSurfaceProperties, Boolean)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo, Int32, GRSurfaceOrigin)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo, Int32, SKSurfaceProperties)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo, Int32, SKSurfaceProps)
Obsolete.

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo, Int32)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo, SKSurfaceProperties)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, Boolean, SKImageInfo)

Creates a new surface whose contents will be drawn to an offscreen render target, allocated by the surface.

Create(GRContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace, SKSurfaceProperties)

Wraps a pre-existing backend 3D API render target as a surface.

Create(GRContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace)

Wraps a pre-existing backend 3D API render target as a surface.

Create(GRContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)

Wraps a pre-existing backend 3D API render target as a surface.

Create(GRContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType)

Wraps a pre-existing backend 3D API render target as a surface.

Create(GRContext, GRBackendRenderTarget, SKColorType, SKSurfaceProperties)

Wraps a pre-existing backend 3D API render target as a surface.

Create(GRContext, GRBackendRenderTarget, SKColorType)

Wraps a pre-existing 3D API render target as a surface.

Create(GRContext, GRBackendRenderTargetDesc, SKSurfaceProps)
Obsolete.

Wraps a pre-existing 3D API render target as a surface.

Create(GRContext, GRBackendRenderTargetDesc)
Obsolete.

Wraps a pre-existing 3D API render target as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace, SKSurfaceProperties)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKSurfaceProperties)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, GRSurfaceOrigin, SKColorType)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, SKColorType, SKSurfaceProperties)

Wraps a pre-existing backend 3D API texture as a surface.

Create(GRContext, GRBackendTexture, SKColorType)

Wraps a pre-existing 3D API texture as a surface.

Create(GRContext, GRBackendTextureDesc, SKSurfaceProps)
Obsolete.

Wraps a pre-existing 3D API texture as a surface.

Create(GRContext, GRBackendTextureDesc)
Obsolete.

Wraps a pre-existing 3D API texture as a surface.

Create(GRContext, GRGlBackendTextureDesc, SKSurfaceProps)
Obsolete.

Wraps a pre-existing OpenGL texture as a surface.

Create(GRContext, GRGlBackendTextureDesc)
Obsolete.

Wraps a pre-existing OpenGL texture as a surface.

Create(GRRecordingContext, Boolean, SKImageInfo, Int32, GRSurfaceOrigin, SKSurfaceProperties, Boolean)

Creates a GPU-accelerated surface with all options including mipmap support.

Create(GRRecordingContext, Boolean, SKImageInfo, Int32, GRSurfaceOrigin)

Creates a GPU-accelerated surface with multisampling and specified origin.

Create(GRRecordingContext, Boolean, SKImageInfo, Int32, SKSurfaceProperties)

Creates a GPU-accelerated surface with multisampling and properties.

Create(GRRecordingContext, Boolean, SKImageInfo, Int32)

Creates a GPU-accelerated surface with multisampling support.

Create(GRRecordingContext, Boolean, SKImageInfo, SKSurfaceProperties)

Creates a GPU-accelerated surface with the specified image info and properties.

Create(GRRecordingContext, Boolean, SKImageInfo)

Creates a GPU-accelerated surface with the specified image info.

Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace, SKSurfaceProperties)

Creates a surface that wraps a GPU backend render target with color space and properties.

Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace)

Creates a surface that wraps a GPU backend render target with color space.

Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)

Creates a surface that wraps a GPU backend render target with origin and properties.

Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType)

Creates a surface that wraps a GPU backend render target with the specified origin.

Create(GRRecordingContext, GRBackendRenderTarget, SKColorType, SKSurfaceProperties)

Creates a surface that wraps a GPU backend render target with surface properties.

Create(GRRecordingContext, GRBackendRenderTarget, SKColorType)

Creates a surface that wraps a GPU backend render target.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace, SKSurfaceProperties)

Creates a surface that wraps a GPU backend texture with all options.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace)

Creates a surface that wraps a GPU backend texture with multisampling and color space.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKSurfaceProperties)

Creates a surface that wraps a GPU backend texture with multisampling and properties.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType)

Creates a surface that wraps a GPU backend texture with multisampling.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)

Creates a surface that wraps a GPU backend texture with origin and properties.

Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, SKColorType)

Creates a surface that wraps a GPU backend texture with the specified origin.

Create(GRRecordingContext, GRBackendTexture, SKColorType, SKSurfaceProperties)

Creates a surface that wraps a GPU backend texture with surface properties.

Create(GRRecordingContext, GRBackendTexture, SKColorType)

Creates a surface that wraps a GPU backend texture.

Create(Int32, Int32, SKColorType, SKAlphaType, IntPtr, Int32, SKSurfaceProps)
Obsolete.

Creates a new surface with the specified image parameters using a provided buffer and surface properties.

Create(Int32, Int32, SKColorType, SKAlphaType, IntPtr, Int32)
Obsolete.

Creates a new surface with the specified image parameters using a provided buffer.

Create(Int32, Int32, SKColorType, SKAlphaType, SKSurfaceProps)
Obsolete.

Creates a new surface with the specified image parameters and surface properties.

Create(Int32, Int32, SKColorType, SKAlphaType)
Obsolete.

Creates a new surface with the specified image parameters.

Create(SKImageInfo, Int32, SKSurfaceProperties)

Creates a new surface from the specified image parameters and surface properties.

Create(SKImageInfo, Int32)

Creates a new surface from the specified image parameters.

Create(SKImageInfo, IntPtr, Int32, SKSurfaceProperties)

Creates a new surface from the specified image parameters, the provided buffer and surface properties.

Create(SKImageInfo, IntPtr, Int32, SKSurfaceProps)
Obsolete.

Creates a new surface from the specified image parameters, the provided buffer and surface properties.

Create(SKImageInfo, IntPtr, Int32, SKSurfaceReleaseDelegate, Object, SKSurfaceProperties)

Creates a new surface with the specified image parameters using a provided buffer.

Create(SKImageInfo, IntPtr, Int32, SKSurfaceReleaseDelegate, Object)

Creates a new surface with the specified image parameters using a provided buffer.

Create(SKImageInfo, IntPtr, Int32)

Creates a new surface with the specified image parameters using a provided buffer.

Create(SKImageInfo, IntPtr, SKSurfaceProperties)

Creates a new surface from the specified image parameters and surface properties.

Create(SKImageInfo, IntPtr)

Creates a new surface with the specified image parameters using a provided buffer.

Create(SKImageInfo, SKSurfaceProperties)

Creates a new surface from the specified image parameters and surface properties.

Create(SKImageInfo, SKSurfaceProps)
Obsolete.

Creates a new surface from the specified image parameters and surface properties.

Create(SKImageInfo)

Creates a new surface with the specified image parameters.

Create(SKPixmap, SKSurfaceProperties)

Creates a new surface with the specified pixmap and surface properties.

Create(SKPixmap, SKSurfaceProps)
Obsolete.

Creates a new surface with the specified pixmap and surface properties.

Create(SKPixmap)

Creates a new surface with the specified pixmap.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace, SKSurfaceProperties)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKSurfaceProperties)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, GRSurfaceOrigin, SKColorType)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, SKColorType, SKSurfaceProperties)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTexture, SKColorType)
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTextureDesc, SKSurfaceProps)
Obsolete.
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRBackendTextureDesc)
Obsolete.
Obsolete.

Wraps a pre-existing backend 3D API texture as a surface.

CreateAsRenderTarget(GRContext, GRGlBackendTextureDesc, SKSurfaceProps)
Obsolete.
Obsolete.

Wraps a pre-existing backend OpenGL texture as a surface.

CreateAsRenderTarget(GRContext, GRGlBackendTextureDesc)
Obsolete.
Obsolete.

Wraps a pre-existing backend OpenGL texture as a surface.

CreateNull(Int32, Int32)

Creates a new surface without any backing pixels.

Dispose()

Releases all resources used by this SKNativeObject.

(Inherited from SKNativeObject)
Dispose(Boolean)

Releases the unmanaged resources used by the SKSurface and optionally releases the managed resources.

DisposeInternal()

Triggers a dispose, ignoring the value of IgnorePublicDispose.

(Inherited from SKNativeObject)
DisposeManaged()

Implemented by derived SKObject types to destroy any managed objects.

(Inherited from SKObject)
DisposeNative()

Implemented by derived SKObject types to destroy any native objects.

(Inherited from SKObject)
DisposeUnownedManaged()

Implemented by derived SKObject types to dispose managed objects that are not owned by this instance.

(Inherited from SKObject)
Draw(SKCanvas, Single, Single, SKPaint)

Draws the current surface on the specified canvas.

Flush()

Ensures all pending draw operations are submitted to the GPU.

Flush(Boolean, Boolean)

Ensures all pending draw operations are submitted to the GPU with specified options.

PeekPixels()

Returns the pixels, if they are available.

PeekPixels(SKPixmap)

Returns the pixmap of the surface.

ReadPixels(SKImageInfo, IntPtr, Int32, Int32, Int32)

Copies the pixels from the surface into the specified buffer.

Snapshot()

Takes a snapshot of the surface and returns it as an image.

Snapshot(SKRectI)

Creates an image from the specified area of the surface.

Applies to