{"id":20745907,"url":"https://github.com/isc30/blazor-canvas","last_synced_at":"2025-09-27T19:31:40.265Z","repository":{"id":92561378,"uuid":"187389892","full_name":"isc30/blazor-canvas","owner":"isc30","description":"Canvas Components for easy graphic rendering (WASM+ServerSide)","archived":false,"fork":false,"pushed_at":"2019-05-19T16:53:31.000Z","size":25,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-17T07:27:40.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isc30.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-18T18:02:06.000Z","updated_at":"2023-10-27T08:14:00.000Z","dependencies_parsed_at":"2023-04-12T07:46:45.299Z","dependency_job_id":null,"html_url":"https://github.com/isc30/blazor-canvas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isc30%2Fblazor-canvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isc30%2Fblazor-canvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isc30%2Fblazor-canvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isc30%2Fblazor-canvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isc30","download_url":"https://codeload.github.com/isc30/blazor-canvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234455926,"owners_count":18835664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T07:23:18.601Z","updated_at":"2025-09-27T19:31:39.828Z","avatar_url":"https://github.com/isc30.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blazor.Canvas\n\nBlazor Canvas Components for easy graphics rendering\n\n## Supported Rendering Contexts\n\n- [x] 2D\n  - [x] WebAssembly\n  - [x] ServerSide Blazor\n- [ ] WebGL (WIP)\n\n## Important Note about Context\n\nCalling JS from .NET is an expensive operation, that's why every operation on the context is being batched.\u003cbr/\u003e\nIt is required to call `Context.RenderAsync()` to actually perform the rendering: it pops all the pending operations and applies them in the browser.\n\n\u003e Please remember to call `Context.RenderAsync()` in the end to actually perform the rendering in the canvas!\n\n## 2D Rendering Context\n\nThe lib includes some components ready to be used for 2D rendering:\n\n- ### `Canvas2DComponent` for static rendering\n\n  This component will render a `canvas` element in the screen and create the 2D context for you.\u003cbr/\u003e\n  Your custom component should inherit from `Canvas2DComponent` and override `OnAfterContextCreatedAsync()`.\u003cbr/\u003e\n  Use `Context` from the base to invoke render operations.\n  \n  ```cs\n  public sealed class HelloCanvas : Canvas2DComponent\n  {\n      protected override async Task OnAfterContextCreatedAsync()\n      {\n          Context.SetFillStyle(\"orange\");\n          Context.FillRect(x: 50, y: 50, width: 50, height: 50);\n\n          await Context.RenderAsync();\n      }\n  }\n  ```\n\n- ### `Surface2DComponent` for realtime rendering\n\n  Same as `Canvas2DComponent`, but this time you will need to override `Task\u003cbool\u003e RequestFrameAsync()`.\u003cbr/\u003e\n  Also, add `[JSInvokable]` to `RequestFrameAsync` so it can be automatically invoked from javascript every frame by the browser (using `requestAnimationFrame` in the background).\u003cbr/\u003e\n  Return `true` from `RequestFrameAsync` if you want a new frame to be requested and `false` if you want to stop the realtime rendering.\n\n  ```cs\n  public sealed class Clock : Surface2DComponent\n  {\n      [JSInvokable(nameof(Clock) + nameof(RequestFrameAsync))]\n      public override async Task\u003cbool\u003e RequestFrameAsync()\n      {\n          Context.Clear(\"white\");\n\n          Context.SetFillStyle(\"black\");\n          Context.SetFont(\"24px Arial\");\n          Context.FillText(DateTime.Now.Millisecond.ToString(), 25, 25);\n\n          await Context.RenderAsync();\n\n          return true;\n      }\n  }\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisc30%2Fblazor-canvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisc30%2Fblazor-canvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisc30%2Fblazor-canvas/lists"}