監視カメラサーバをPCで動かしているんだが、別のところでも同じ画面が見たい
ただ複数のクライアントを動かすとサーバの負荷があがるので、台数が増やせない
というニッチな要望に対応したバッチファイル
参考にした(というより、丸パク)のは、
使用例:
ネットワークドライブを d: に割り当てる
capture.bat を実行すると 10秒ごとに d:/screenshot.png を作成する
別のPCで d: をマウントして、screen.html をブラウザで開くだけ
oneDrive と組み合わせるとか Webserver を組み合わせて スマホで見るとかもあり
capture.bat
@echo off
cd /d %~dp0
:最小化状態で実行する
if not "%X_MIMIMIZED%"=="1" (
set X_MIMIMIZED=1
start /min cmd /c,"%~0" %*
exit
)
:これ以下に必要な処理を書く
echo "最小化!"
:loop
powershell.exe -File cap.ps1
timeout /t 10
goto loop
cap.ps1
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 2560, 1080)
screenshot $bounds "d:\screenshot.png"
screen.html
<head>
<meta http-equiv="refresh" content="10" />
</head>
<img src=screenshot.png>