Share via


ISurfaceHolder.LockCanvas Method

Definition

Overloads

LockCanvas()

Start editing the pixels in the surface.

LockCanvas(Rect)

Just like #lockCanvas() but allows specification of a dirty rectangle.

LockCanvas()

Start editing the pixels in the surface.

[Android.Runtime.Register("lockCanvas", "()Landroid/graphics/Canvas;", "GetLockCanvasHandler:Android.Views.ISurfaceHolderInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Android.Graphics.Canvas? LockCanvas ();
[<Android.Runtime.Register("lockCanvas", "()Landroid/graphics/Canvas;", "GetLockCanvasHandler:Android.Views.ISurfaceHolderInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member LockCanvas : unit -> Android.Graphics.Canvas

Returns

Canvas Use to draw into the surface.

Attributes

Remarks

Start editing the pixels in the surface. The returned Canvas can be used to draw into the surface's bitmap. A null is returned if the surface has not been created or otherwise cannot be edited. You will usually need to implement Callback#surfaceCreated Callback.surfaceCreated to find out when the Surface is available for use.

The content of the Surface is never preserved between unlockCanvas() and lockCanvas(), for this reason, every pixel within the Surface area must be written. The only exception to this rule is when a dirty rectangle is specified, in which case, non-dirty pixels will be preserved.

If you call this repeatedly when the Surface is not ready (before Callback#surfaceCreated Callback.surfaceCreated or after Callback#surfaceDestroyed Callback.surfaceDestroyed), your calls will be throttled to a slow rate in order to avoid consuming CPU.

If null is not returned, this function internally holds a lock until the corresponding #unlockCanvasAndPost call, preventing SurfaceView from creating, destroying, or modifying the surface while it is being drawn. This can be more convenient than accessing the Surface directly, as you do not need to do special synchronization with a drawing thread in Callback#surfaceDestroyed Callback.surfaceDestroyed.

Java documentation for android.view.SurfaceHolder.lockCanvas().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

LockCanvas(Rect)

Just like #lockCanvas() but allows specification of a dirty rectangle.

[Android.Runtime.Register("lockCanvas", "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;", "GetLockCanvas_Landroid_graphics_Rect_Handler:Android.Views.ISurfaceHolderInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Android.Graphics.Canvas? LockCanvas (Android.Graphics.Rect? dirty);
[<Android.Runtime.Register("lockCanvas", "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;", "GetLockCanvas_Landroid_graphics_Rect_Handler:Android.Views.ISurfaceHolderInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member LockCanvas : Android.Graphics.Rect -> Android.Graphics.Canvas

Parameters

dirty
Rect

Area of the Surface that will be modified.

Returns

Canvas Use to draw into the surface.

Attributes

Remarks

Just like #lockCanvas() but allows specification of a dirty rectangle. Every pixel within that rectangle must be written; however pixels outside the dirty rectangle will be preserved by the next call to lockCanvas().

Java documentation for android.view.SurfaceHolder.lockCanvas(android.graphics.Rect).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to