excubo-ag / Blazor.Canvas

Home Page:https://excubo-ag.github.io/Blazor.Canvas/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offscreen canvas

Urantij opened this issue · comments

Hi.
Iam trying to create an offscreen canvas with your library.

If i understood correctly CanvasHelper.cs code, you find canvas on the page, and then call getContext on it.
But i cant find a way to use canvas, which is not part of the page.

Hi @Urantij,

sorry for the slow response. This is actually a very good request, so I've decided to quickly add support for this. Version 2.5.0 supports this. Simply use offscreen_context = await CanvasHelper.GetContext2DAsync(js, "window.OffscreenCanvas");. This assumes that there is an OffscreenCanvas object already present (create with e.g. await js.InvokeVoidAsync("eval", "window.OffscreenCanvas = new OffscreenCanvas(400, 400)");).
https://excubo-ag.github.io/Blazor.Canvas/2D/offscreen shows this feature. The corresponding code can be found here: https://github.com/excubo-ag/Blazor.Canvas/blob/main/TestProject_Components/Pages/Context2D/Offscreen.razor

Best regards
Stefan