IPCamera.cs
1.8 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
52
53
54
55
56
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace DeviceLibrary
{
public class IPCamera
{
public IPCamera()
{
string ip = Setting_Init.UploadVideo_ServiceIp;
int port = Setting_Init.UploadVideo_ServicePort;
server=($"http://{ip}:{port}");
}
string server;
string Addr_getImgBase64 = "/cam/grabOneImgByBase64";
public string GetImgBase64(string cameName)
{
string base64 = "";
try
{
Dictionary<string, string> dic = new Dictionary<string, string>()
{
{ "camName",cameName },
{"width",Setting_Init.UploadVideo_ImgWidth.ToString() },
{"height",Setting_Init.UploadVideo_ImgHeight.ToString()},
{"quality",Setting_Init.UploadVideo_ImgQuality.ToString()},
};
base64 = HttpHelper.Get(GetAddr(Addr_getImgBase64, dic),false);
}
catch (Exception ex)
{
LogUtil.error($"{cameName} 采集异常", ex);
}
return base64;
}
string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
}
}