From f48a58c8a5bf4b1eb3711662fb330116074d6566 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sun, 12 Nov 2023 19:09:24 -0500 Subject: [PATCH] InitClear du canvas --- BlazorCanvas/BlazorCanvas/Data/CanvasCommand.cs | 2 -- BlazorCanvas/BlazorCanvas/Data/CanvasService.cs | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BlazorCanvas/BlazorCanvas/Data/CanvasCommand.cs b/BlazorCanvas/BlazorCanvas/Data/CanvasCommand.cs index 1889188..0dcf53c 100644 --- a/BlazorCanvas/BlazorCanvas/Data/CanvasCommand.cs +++ b/BlazorCanvas/BlazorCanvas/Data/CanvasCommand.cs @@ -1,7 +1,5 @@ namespace BlazorCanvas.Data; -// https://www.codeproject.com/Articles/5269947/Drawing-with-the-HTML-Canvas-Element-in-Blazor-Ser - public class CanvasCommand { public double X { get; set; } public double Y { get; set; } diff --git a/BlazorCanvas/BlazorCanvas/Data/CanvasService.cs b/BlazorCanvas/BlazorCanvas/Data/CanvasService.cs index 0e6e351..10e1ce3 100644 --- a/BlazorCanvas/BlazorCanvas/Data/CanvasService.cs +++ b/BlazorCanvas/BlazorCanvas/Data/CanvasService.cs @@ -11,6 +11,8 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels; namespace BlazorCanvas.Data; +// https://www.codeproject.com/Articles/5269947/Drawing-with-the-HTML-Canvas-Element-in-Blazor-Ser + public class CanvasService { private Canvas2DContext? _currentCanvasContext; private IJSRuntime _jsRuntime; @@ -29,8 +31,10 @@ public class CanvasService { // TODO: Dessiner à partir des commandes de Franz. public async void Draw(IEnumerable lscommand) { - if (_currentCanvasContext is null) + if (_currentCanvasContext is null) { _currentCanvasContext = await myCanvas.CreateCanvas2DAsync(); + await _currentCanvasContext.ClearRectAsync(0, 0, 1920, 1080); + } await _currentCanvasContext.BeginBatchAsync(); foreach (CanvasCommand command in lscommand) { await _currentCanvasContext.SetFillStyleAsync(command.Color); @@ -40,8 +44,10 @@ public class CanvasService { } public async void Draw(CanvasCommand command) { - if (_currentCanvasContext is null) + if (_currentCanvasContext is null) { _currentCanvasContext = await myCanvas.CreateCanvas2DAsync(); + await _currentCanvasContext.ClearRectAsync(0, 0, 1920, 1080); + } await _currentCanvasContext.SetFillStyleAsync(command.Color); await _currentCanvasContext.FillRectAsync(command.X, command.Y, command.PointSize, command.PointSize); }