OffscreenCanvas Class
A canvas that is not in a document (https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface): created in a window or in a worker, or by transferControlToOffscreen() for a canvas element (its placeholder), whose frames are then displayed by the element. It is transferable (to a worker), and needs a rendering backend for its 2D context.
public sealed class OffscreenCanvas : EventTarget- Inheritance
EventTargetOffscreenCanvas
Constructors
| Name | Description |
|---|---|
| OffscreenCanvas(ulong, ulong) | Creates an OffscreenCanvas of the given size, without context (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas). |
OffscreenCanvas(ulong, ulong)
OffscreenCanvas.csCreates an OffscreenCanvas of the given size, without context (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas).
Parameters
See also
Properties
| Name | Description |
|---|---|
| Height | Gets or sets the height of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-height): setting it resets the bitmap and the 2D context. |
| OnContextLost | Gets or sets the event handler of the contextlost event (never fired). |
| OnContextRestored | Gets or sets the event handler of the contextrestored event (never fired). |
| Width | Gets or sets the width of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-width): setting it resets the bitmap and the 2D context. |
Height
OffscreenCanvas.csGets or sets the height of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-height): setting it resets the bitmap and the 2D context.
public ulong Height { get; set; }OnContextLost
OffscreenCanvas.csGets or sets the event handler of the contextlost event (never fired).
OnContextRestored
OffscreenCanvas.csGets or sets the event handler of the contextrestored event (never fired).
Width
OffscreenCanvas.csGets or sets the width of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-width): setting it resets the bitmap and the 2D context.
public ulong Width { get; set; }Methods
| Name | Description |
|---|---|
| ConvertToBlob(ImageEncodeOptions?) | Returns a Blob of the bitmap serialized as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-converttoblob): PNG, JPEG or WebP (another type is serialized as PNG). |
| GetContext(OffscreenRenderingContextId, CanvasRenderingContext2DSettings?) | Returns the rendering context of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-getcontext): an OffscreenCanvasRenderingContext2D for "2d" (null without rendering backend), an ImageBitmapRenderingContext for "bitmaprenderer", or null for another type or when the canvas already has a context of another type. |
| TransferToImageBitmap() | Returns an ImageBitmap of the bitmap and replaces the bitmap with a new transparent black bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-transfertoimagebitmap). |
ConvertToBlob(ImageEncodeOptions?)
OffscreenCanvas.csReturns a Blob of the bitmap serialized as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-converttoblob): PNG, JPEG or WebP (another type is serialized as PNG).
public Task<Blob> ConvertToBlob(ImageEncodeOptions? options = null)Parameters
optionsImageEncodeOptions?
Returns
Task<Blob> A task completed in a task of the event loop; it fails with an InvalidStateError when the canvas is detached, a SecurityError when it is not origin-clean, an IndexSizeError when it has no pixels.
See also
GetContext(OffscreenRenderingContextId, CanvasRenderingContext2DSettings?)
OffscreenCanvas.csReturns the rendering context of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-getcontext): an OffscreenCanvasRenderingContext2D for "2d" (null without rendering backend), an ImageBitmapRenderingContext for "bitmaprenderer", or null for another type or when the canvas already has a context of another type.
public object? GetContext(OffscreenRenderingContextId contextId, CanvasRenderingContext2DSettings? options = null)Parameters
contextIdOffscreenRenderingContextIdoptionsCanvasRenderingContext2DSettings?
Returns
Exceptions
DomException- An
InvalidStateErrorwhen the canvas is detached.
See also
TransferToImageBitmap()
OffscreenCanvas.csReturns an ImageBitmap of the bitmap and replaces the bitmap with a new transparent black bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-transfertoimagebitmap).
public ImageBitmap TransferToImageBitmap()Returns
Exceptions
DomException- An
InvalidStateErrorwhen the canvas is detached or has no context.