-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainComponent.razor
More file actions
51 lines (38 loc) · 1.43 KB
/
Copy pathMainComponent.razor
File metadata and controls
51 lines (38 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@using System.Threading
<nav class="navbar navbar-expand-lg navbar-dark bg-dark px-4">
<a class="navbar-brand" href="#">Blazor Object Detection</a>
</nav>
<main class="p-4">
<div class="mb-3">
<button class="btn btn-sm btn-primary" @onclick="OnClick">Restart</button>
</div>
<div>
<img height="416" width="416" src="@Bitmap" />
</div>
</main>
@code {
public VideoCaptureService VideoCaptureService { get; set; }= new VideoCaptureService();
public CancellationTokenSource CancellationTokenSource { get; set; }
public string Bitmap { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
CancellationTokenSource = new CancellationTokenSource();
VideoCaptureService.Snapshot += VideoCaptureService_Snapshot;
await VideoCaptureService.ExecuteAsync(CancellationTokenSource.Token);
}
private async Task OnClick()
{
CancellationTokenSource = new CancellationTokenSource();
VideoCaptureService.Snapshot += VideoCaptureService_Snapshot;
await VideoCaptureService.ExecuteAsync(CancellationTokenSource.Token);
}
private async void VideoCaptureService_Snapshot(string bitmap)
{
await InvokeAsync(() =>
{
Bitmap = $"data:image/jpg;base64,{bitmap}";
StateHasChanged();
});
}
}