Editar

Compartilhar 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 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

Canvas

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

Context
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 a value indicating whether this object should destroy the underlying native object.

(Inherited from SKObject)
SurfaceProperties

Gets the surface property configuration.

SurfaceProps
Obsolete.

Gets the surface property configuration.

Methods

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)
Create(GRRecordingContext, Boolean, SKImageInfo, Int32, GRSurfaceOrigin)
Create(GRRecordingContext, Boolean, SKImageInfo, Int32, SKSurfaceProperties)
Create(GRRecordingContext, Boolean, SKImageInfo, Int32)
Create(GRRecordingContext, Boolean, SKImageInfo, SKSurfaceProperties)
Create(GRRecordingContext, Boolean, SKImageInfo)
Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKColorSpace)
Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendRenderTarget, GRSurfaceOrigin, SKColorType)
Create(GRRecordingContext, GRBackendRenderTarget, SKColorType, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendRenderTarget, SKColorType)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKColorSpace)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, Int32, SKColorType)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, SKColorType, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendTexture, GRSurfaceOrigin, SKColorType)
Create(GRRecordingContext, GRBackendTexture, SKColorType, SKSurfaceProperties)
Create(GRRecordingContext, GRBackendTexture, SKColorType)
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() (Inherited from SKObject)
Draw(SKCanvas, Single, Single, SKPaint)

Draws the current surface on the specified canvas.

Flush()
Flush(Boolean, Boolean)
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)

Applies to