刚接触摄像头代码的编写,这里记录一下吧!记录一下我挨打的过程!!
在摄像头里面添加字符串,困扰了很久,资料也看了很多,海康官网的文档看了也不是很懂,说白了,就是想CV,嗐!
请求同事帮忙,我们一起试了四五种方法,终于成功了一个,代码如下:
private void btnAdd_Click(object sender, EventArgs e)
{
foreach (VideoForm mf in MainForm.m_videoformCs)
{
if (mf.m_lUserID == 0)
{
mf.ReLogin();//重要 判断小于0 后文字信息加不上;不判断则能添加上去但是Video Info窗体一直不退出一直提示没设备;删除则视频直接不显示;
}
List List = new List();
Font F = new Font("黑体", 18, FontStyle.Italic | FontStyle.Bold);
Point P = new Point(10, 50);
ShowText text = new ShowText();
text.Text = idText.Text + " " + nameText.Text + " " + fxText.Text + "\r\n" + userText.Text + " " + videoPlaceText.Text + " " + videoDwText.Text + "\r\n" + "管径:" + gjText.Text + " " + "埋深:" + msText.Text + " " + "材质:" + czText.Text;
text.Ft = F;
text.Pt = P;
text.Color = Color.Aqua;
List.Add(text);
mf.List = List;
}
}
VideoForm为显示视频得控件; MainForm是主窗体;m_lUserID是NET_DVR_Login_V40登录返回值;ReLogin();是重新登录的方法;idText.Text类似的都是输入值;
显示效果不佳,文字闪烁的很厉害,用我老大的话来说就是会闪没了;另外一个提示说需要重新写解编码器,我是崩溃的;
昨天因为录制视频一直不成功然后更改了窗体布局,不得不重新来选择字符的叠加,然再次百度时看到了以下代码:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct NET_DVR_SHOWSTRING_V30
{
///
/// 结构体大小
///
public int dwSize;
///
/// 要显示的字符内容
///
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 8)]
public NET_DVR_SHOWSTRINGINFO[] struStringInfo;
};
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct NET_DVR_SHOWSTRINGINFO
{
///
/// 预览的图象上是否显示字符,0-不显示,1-显示 区域大小704*576,单个字符的大小为32*32
///
public ushort wShowString;
///
/// 该行字符的长度,不能大于44个字符
///
public ushort wStringSize;
///
/// 字符显示位置的x坐标
///
public ushort wShowStringTopLeftX;
///
/// 字符名称显示位置的y坐标
///
public ushort wShowStringTopLeftY;
///
/// 要显示的字符内容
///
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 44)]
public string sString;
}
//设置服务器参数
[DllImport("HCNetSDK.dll")]
public static extern int NET_DVR_SetDVRConfig(int lUserID, int dwCommand, int lChannel, IntPtr lpInBuffer, int dwInBufferSize);
[DllImport("HCNetSDK.dll")]
public static extern int NET_DVR_GetDVRConfig(int lUserID, int dwCommand, int lChannel, IntPtr lpInBuffer, int dwInBufferSize, ref int len);
public void InfoBtn_Click(object sender, EventArgs e)
{
NET_DVR_SHOWSTRING_V30 ShowStruct = new NET_DVR_SHOWSTRING_V30();
int len = 0;
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ShowStruct));
Marshal.StructureToPtr(ShowStruct, ptr, false);
int err = NET_DVR_GetDVRConfig(m_lUserID, 1030, 1, ptr, Marshal.SizeOf(ShowStruct), ref len);
ShowStruct = (NET_DVR_SHOWSTRING_V30)Marshal.PtrToStructure(ptr, typeof(NET_DVR_SHOWSTRING_V30));
ShowStruct.struStringInfo[0].sString = "你好呀!我是用来测试的叠加字符串!!!";
ShowStruct.struStringInfo[0].wShowString = 1;
ShowStruct.struStringInfo[0].wShowStringTopLeftX = 10;
ShowStruct.struStringInfo[0].wShowStringTopLeftY = 10;
ShowStruct.struStringInfo[0].wStringSize = 44;
IntPtr ptrNow = Marshal.AllocCoTaskMem(Marshal.SizeOf(ShowStruct));
Marshal.StructureToPtr(ShowStruct, ptrNow, false);
err = NET_DVR_SetDVRConfig(m_lUserID, 1031, 1, ptrNow, Marshal.SizeOf(ShowStruct));
//return err;
}
添加后显示效果如图:
愚笨的我又遇到了几个问题,
要如何把我写入的值全部显示出来呢???
NET_DVR_SaveRealData保存视频文件没有内容(即大小为0KB),获取报错值为12(说是:请先打开预览),关键是我预览是打开的NET_DVR_RealPlay_V40的返回值m_lRealHandle也是有值的,还是不行!所以我要怎么才能保存视频???
求解!!!
欢迎知道的大神分享!!!
请求知道的大神指教!!!
代码是Right Here 的专栏_Softwaring_CSDN博客-Linux,Others,Windows领域博主在关于字幕叠加(远程控制),如何实现?[c#][海康]-CSDN社区这里回复的,我看了博主的专栏,没有专门发布过,不忍心就这样看着这个方法石沉大海,所以冒昧以原创来发布了,感谢博主!!!