记海康摄像头获取保存截图的一个方法(c#)

记海康摄像头获取保存截图的一个方法(c#)

先获取海康摄像头接口信息

引入模块

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Configuration;
using System.Net;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Security.Cryptography;
using System.Xml;

方法编写

//保存网络图片(流保存成图片)
   private string GetMethodImage(string pathFile, byte[] imgbit)
    {
       
        //判断文件夹是否存在
        if (!Directory.Exists(pathFile))
        {
            Directory.CreateDirectory(pathFile);
        }
        pathFile += $@"{DateTime.Now.ToString("yyMMddHHmmss")}.jpg";
        WriteBytesToFile(pathFile, imgbit);
        return pathFile;
    }

    public static void WriteBytesToFile(string fileName, byte[] content)
    {
        FileStream fs = new FileStream(fileName, FileMode.Create);
        BinaryWriter w = new BinaryWriter(fs);
        try
        {
            w.Write(content);
        }
        finally
        {
            fs.Close();
            w.Close();
        }

    }
     static byte[] GetUrlToImage(string Url, string User, string password)
    {
        System.Net.WebRequest WebRequest = System.Net.WebRequest.Create(Url);
        WebRequest.Method = "GET";
        NetworkCredential d = new NetworkCredential(User,password);
        WebRequest.Credentials = d;
        Byte[] filebyteArray;
        try
        {
            using (WebResponse webRes = WebRequest.GetResponse())
            {
				int length = (int)webRes.ContentLength;
                HttpWebResponse response = webRes as HttpWebResponse;
                Stream stream = response.GetResponseStream();
                MemoryStream MemoryStream = new MemoryStream();
                byte[] buffer = new byte[length];
                int i;
                while ((i = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    MemoryStream.Write(buffer, 0, i);
                }
                filebyteArray = MemoryStream.ToArray(); //获取图像字节流
                //string st3 = Convert.ToBase64String(filebyteArray); //BASE64编码
                MemoryStream.Close();
                //return st3;//返回BASE64编码
                return filebyteArray;//返回图像字节流
            }
        }
        catch {
            return null;
        }
    }

方法调用

string STCD=90000000; //摄像头编号
string pathFile = “C:\Users\Desktop\testpic” + string.Format("\{0}\{1}\{2}\", DateTime.Now.ToString(“yyyy”), DateTime.Now.ToString(“MMdd”),STCD);
//按时间生成文件夹路径,这里是:“C:\Users\Desktop\testpic” +\2023\0320\90000000
string picurl = “http://IP:port/ISAPI/Streaming/channels/101/picture”; //IP:port替换为你实际的摄像头IP,101指IP通道号,第二支为201
string User = “admin”; //海康摄像头登录账号
string password = “password”; //海康摄像头登录密码
byte[] ImgBit = null;
ImgBit = GetUrlToImage(picurl, User,password);//调用取流方法,返回图片字节流
//ImgBit可以直接存入sqlserver,字段类型为image
string savepath = GetMethodImage(pathFile, ImgBit); //调用保存图片方法,返回保存路径
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
海康摄像头录调整云台操作是指海康摄像头通过调整云台的操作来进行录像录。云台是摄像头上的一个部件,可以对摄像头进行方向和角度的调整。 海康摄像头录调整云台操作的目的是为了能够更灵活地调整摄像头的视角,以便获取更好的录像效果。通过调整云台,可以使摄像头旋转和倾斜,从而可以实现全方位的监控。 海康摄像头录调整云台操作的具体步骤如下: 1. 首先,进入摄像头的设置界面,在设置界面中找到云台控制选项。 2. 在云台控制选项中,选择要调整的摄像头。如果有多个摄像头,可以选择其中一个进行调整。 3. 点击调整按钮,进入云台调整界面。在这个界面上,可以看到摄像头的当前位置和角度。 4. 通过云台调整界面上的按钮或者滑块,调整摄像头的方向和角度。可以选择向左或向右旋转,向上或向下倾斜等。 5. 调整完成后,点击确认按钮保存设置。此时,摄像头录下调整后的位置和角度。 通过以上步骤,海康摄像头就可以录调整云台操作了。录像录的信息包括调整前后的位置和角度,以及调整的时间。这样,用户就可以根据需要进行相应的回放和查看操作。海康摄像头录调整云台操作的功能方便用户根据实际需要进行自定义的监控视角设置,提升了监控系统的灵活性和使用效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值