HtmlCanvasElement Class
https://html.spec.whatwg.org/multipage/canvas.html#htmlcanvaselement
public sealed class HtmlCanvasElement : HtmlElement- Inheritance
HtmlElementHtmlCanvasElement
Properties
| Name | Description |
|---|---|
| Height | https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-height |
| Width | https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-width |
Height
HandWrittenReflection.cshttps://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-height
public uint Height { get; set; }Property value
Exceptions
DomException- An
InvalidStateErrorwhen the canvas is the placeholder of anOffscreenCanvas.
See also
https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-width
public uint Width { get; set; }Property value
Exceptions
DomException- An
InvalidStateErrorwhen the canvas is the placeholder of anOffscreenCanvas.
See also
Methods
| Name | Description |
|---|---|
| GetContext(string, CanvasRenderingContext2DSettings?) | Returns the rendering context of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext): a CanvasRenderingContext2D for "2d" and an ImageBitmapRenderingContext for "bitmaprenderer" (created the first time), or null for a context type that is not supported ("webgl", "webgl2", "webgpu") or that does not match the context of the canvas. The 2D context needs a rendering backend (BrowsingContextOptions.RenderingBackend): without one, getContext("2d") returns null. |
| ToBlob(BlobCallback, string, double?) | Serializes the bitmap as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob) and invokes the callback with a Blob of the file in a task (null when the canvas has no pixels). |
| ToDataUrl(string, double?) | Returns a data: URL of the bitmap serialized as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl): PNG, JPEG or WebP (another type is serialized as PNG), or data:, when the canvas has no pixels. |
| TransferControlToOffscreen() | Transfers the control of the canvas to an OffscreenCanvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-transfercontroltooffscreen): the canvas becomes its placeholder and displays the frames drawn by its rendering context (e.g. in a worker). |
GetContext(string, CanvasRenderingContext2DSettings?)
EmbeddedContent.csReturns the rendering context of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext): a CanvasRenderingContext2D for "2d" and an ImageBitmapRenderingContext for "bitmaprenderer" (created the first time), or null for a context type that is not supported ("webgl", "webgl2", "webgpu") or that does not match the context of the canvas. The 2D context needs a rendering backend (BrowsingContextOptions.RenderingBackend): without one, getContext("2d") returns null.
public object? GetContext(string contextId, CanvasRenderingContext2DSettings? options = null)Parameters
contextIdstring- The type of the context.
optionsCanvasRenderingContext2DSettings?- The options of the context.
Returns
object? The context, or null.
Exceptions
DomException- An
InvalidStateErrorwhen the canvas is the placeholder of anOffscreenCanvas.
See also
ToBlob(BlobCallback, string, double?)
EmbeddedContent.csSerializes the bitmap as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob) and invokes the callback with a Blob of the file in a task (null when the canvas has no pixels).
public void ToBlob(BlobCallback callback, string type = "image/png", double? quality = null)Parameters
callbackBlobCallback- The callback.
typestring- The MIME type of the file (PNG, JPEG or WebP; another type is serialized as PNG).
qualitydouble?- The quality of the lossy formats: a number from 0 to 1, else the default quality.
Exceptions
DomException- An
InvalidStateErrorfor the placeholder of anOffscreenCanvas, aSecurityErrorwhen the canvas is not origin-clean.
See also
ToDataUrl(string, double?)
EmbeddedContent.csReturns a data: URL of the bitmap serialized as an image file (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl): PNG, JPEG or WebP (another type is serialized as PNG), or data:, when the canvas has no pixels.
Parameters
typestring- The MIME type of the file.
qualitydouble?- The quality of the lossy formats from 0 to 1 (another value is the default quality), or null for the default quality.
Returns
Exceptions
DomException- A
SecurityErrorwhen the canvas is not origin-clean.
See also
TransferControlToOffscreen()
EmbeddedContent.csTransfers the control of the canvas to an OffscreenCanvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-transfercontroltooffscreen): the canvas becomes its placeholder and displays the frames drawn by its rendering context (e.g. in a worker).
public OffscreenCanvas TransferControlToOffscreen()Returns
Exceptions
DomException- An
InvalidStateErrorwhen the canvas has a context or was already transferred.