From 03e8977bbf085a8e341475b8d9639de98fefe9e3 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 24 Dec 2025 15:22:57 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=A0=81=E4=B8=BA=20100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/HikVisionWebPlugin.razor.cs | 6 +++--- .../BootstrapBlazor.HikVision/wwwroot/hikvision.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index 3e4e09ec..1678a6d6 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -280,7 +280,7 @@ public async Task OpenSound() if (IsLogin && IsRealPlaying) { var code = await InvokeAsync("openSound", Id); - ret = code == 0; + ret = code == 100; } return ret; } @@ -295,7 +295,7 @@ public async Task CloseSound() if (IsLogin && IsRealPlaying) { var code = await InvokeAsync("closeSound", Id); - ret = code == 0; + ret = code == 100; } return ret; } @@ -311,7 +311,7 @@ public async Task SetVolume(int value) if (IsLogin && IsRealPlaying) { var code = await InvokeAsync("setVolume", Id, Math.Max(0, Math.Min(100, value))); - ret = code == 0; + ret = code == 100; } return ret; } diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index f49fbb05..a2e7ff9c 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -355,7 +355,7 @@ export async function openSound(id) { return 101; } - let code = 0; + let code = 100; try { await WebVideoCtrl.I_OpenSound(iWndIndex); } @@ -374,7 +374,7 @@ export async function closeSound(id) { return 101; } - let code = 0; + let code = 100; try { await WebVideoCtrl.I_CloseSound(iWndIndex); } @@ -398,7 +398,7 @@ export async function setVolume(id, value) { v = 50; } - let code = 0; + let code = 100; try { await WebVideoCtrl.I_SetVolume(Math.min(100, Math.max(0, v))); } From 1015de54ef64a95de2c9dfad21df1dbed60ffaa7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 24 Dec 2025 15:23:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(HikVision):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8A=93=E5=9B=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/HikVisionWebPlugin.razor.cs | 40 +++++++++++++++++++ .../Components/HikVisionWebPlugin.razor.js | 4 +- .../wwwroot/hikvision.js | 30 ++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index 1678a6d6..bc02d5ca 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -315,4 +315,44 @@ public async Task SetVolume(int value) } return ret; } + + private TaskCompletionSource? _captureTaskCompletionSource = null; + + /// + /// 抓图方法返回 Url + /// + /// + public async Task CapturePicture(CancellationToken token = default) + { + IJSStreamReference? ret = null; + if (IsLogin && IsRealPlaying) + { + _captureTaskCompletionSource = new(); + + try + { + await InvokeVoidAsync("capturePicture", token, Id); + ret = await _captureTaskCompletionSource.Task; + } + catch (Exception ex) + { + _captureTaskCompletionSource.SetException(ex); + } + } + return ret; + } + + /// + /// 抓图返回文件流方法 由 Javascript 调用 + /// + /// + /// + [JSInvokable] + public async Task TriggerReceivePictureStream(IJSStreamReference stream) + { + if (_captureTaskCompletionSource != null) + { + _captureTaskCompletionSource.SetResult(stream); + } + } } diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js index 290de54d..07009e82 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js @@ -1,4 +1,4 @@ -import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, dispose as disposeVision } from '../hikvision.js'; +import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, dispose as disposeVision } from '../hikvision.js'; import Data from '../../BootstrapBlazor/modules/data.js'; export async function init(id, invoke) { @@ -29,7 +29,7 @@ export async function login(id, ip, port, userName, password, loginType) { return logined; } -export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume } +export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload } export function dispose(id) { disposeVision(id); diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index a2e7ff9c..f5e1d725 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -409,6 +409,36 @@ export async function setVolume(id, value) { return code; } +export async function capturePicture(id) { + const vision = Data.get(id); + const { iWndIndex, realPlaying, invoke } = vision; + + if (realPlaying !== true) { + return ""; + } + + try { + const base64 = await WebVideoCtrl.I_CapturePicData(); + const bytes = base64ToArray(base64); + return DotNet.createJSStreamReference(bytes.buffer); + } + catch (ex) { + return null; + } +} + +const base64ToArray = base64String => { + const base64Data = base64String.split(',')[1] || base64String; + const binaryString = atob(base64Data); + const length = binaryString.length; + const bytes = new Uint8Array(length); + + for (let i = 0; i < length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + + return bytes; +} export function dispose(id) { const vision = Data.get(id); const { realPlaying, logined, observer } = vision; From ac070e8ef28a2aaf3783472f59da3f6609da0cbf Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 24 Dec 2025 15:23:44 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=8A=93?= =?UTF-8?q?=E5=9B=BE=E5=B9=B6=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/HikVisionWebPlugin.razor.cs | 12 ++++++++++++ .../wwwroot/hikvision.js | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index bc02d5ca..2716acef 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -316,6 +316,18 @@ public async Task SetVolume(int value) return ret; } + /// + /// 抓图方法返回 Url + /// + /// + public async Task CapturePictureAndDownload() + { + if (IsLogin && IsRealPlaying) + { + var stream = await InvokeAsync("capturePictureAndDownload", Id); + } + } + private TaskCompletionSource? _captureTaskCompletionSource = null; /// diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index f5e1d725..b0699ff0 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -439,6 +439,25 @@ const base64ToArray = base64String => { return bytes; } + +export function capturePictureAndDownload(id) { + const vision = Data.get(id); + const { iWndIndex, realPlaying, invoke } = vision; + + if (realPlaying !== true) { + return ""; + } + + try { + const base64 = await WebVideoCtrl.I_CapturePicData(); + const bytes = base64ToArray(base64); + return DotNet.createJSStreamReference(bytes.buffer); + } + catch (ex) { + return null; + } +} + export function dispose(id) { const vision = Data.get(id); const { realPlaying, logined, observer } = vision; From a7f8a935d9f1d2fec2577a43bb3ee05e1337e285 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 24 Dec 2025 16:34:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/HikVisionWebPlugin.razor.cs | 2 +- .../wwwroot/hikvision.js | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index 2716acef..88712dae 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -324,7 +324,7 @@ public async Task CapturePictureAndDownload() { if (IsLogin && IsRealPlaying) { - var stream = await InvokeAsync("capturePictureAndDownload", Id); + await InvokeVoidAsync("capturePictureAndDownload", Id); } } diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index b0699ff0..7e8f8be2 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -410,8 +410,8 @@ export async function setVolume(id, value) { } export async function capturePicture(id) { - const vision = Data.get(id); - const { iWndIndex, realPlaying, invoke } = vision; + const vision = Data.get(id); + const { realPlaying } = vision; if (realPlaying !== true) { return ""; @@ -419,8 +419,10 @@ export async function capturePicture(id) { try { const base64 = await WebVideoCtrl.I_CapturePicData(); - const bytes = base64ToArray(base64); - return DotNet.createJSStreamReference(bytes.buffer); + if (base64) { + const bytes = base64ToArray(base64); + return DotNet.createJSStreamReference(bytes.buffer); + } } catch (ex) { return null; @@ -440,21 +442,27 @@ const base64ToArray = base64String => { return bytes; } -export function capturePictureAndDownload(id) { +export async function capturePictureAndDownload(id) { const vision = Data.get(id); - const { iWndIndex, realPlaying, invoke } = vision; + const { realPlaying } = vision; if (realPlaying !== true) { - return ""; + return; } try { const base64 = await WebVideoCtrl.I_CapturePicData(); - const bytes = base64ToArray(base64); - return DotNet.createJSStreamReference(bytes.buffer); + if (base64) { + const anchorElement = document.createElement('a'); + anchorElement.href = `data:image/jpg;base64,${base64}`; + anchorElement.download = `capture_${new Date().getTime()}.jpg`; + document.body.appendChild(anchorElement); + anchorElement.click(); + document.body.removeChild(anchorElement); + } } catch (ex) { - return null; + } } From 65b05de34c19c041aebfb612ec84c464bb99180a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 25 Dec 2025 08:53:51 +0800 Subject: [PATCH 5/5] chore: bump version 10.0.6 --- .../BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj index e35c13f3..d1ed5412 100644 --- a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj +++ b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj @@ -1,7 +1,7 @@ - 10.0.5 + 10.0.6