关于字幕叠加(远程控制),如何实现?[c#][海康]

pfworld 2010-06-21 06:11:38


[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct NET_DVR_SHOWSTRINGINFO
{
//编码端字符叠加配置结构
public ushort dwShowString;
public int wStringSize;
public ushort wShowStringTopLeftX;
public ushort wShowStringTopLeftY;
//[MarshalAs(UnmanagedType.LPArray, SizeConst = 44)]
//public char[] sString;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 44)]
public string sString;

}


[StructLayout(LayoutKind.Sequential)]
public struct NET_DVR_SHOWSTRING
{
//叠加字符结构
public int dwSize;
public NET_DVR_SHOWSTRINGINFO struStringInfo;
}


//编码端叠加字符
[DllImport("HCNetSDK.dll")]
public static extern bool NET_DVR_SetDVRConfig(int lUserID, int dwCommand, int lChannel, NET_DVR_SHOWSTRING lpInBuffer, int dwInBufferSize);


private void button5_Click(object sender, EventArgs e)
{
NET_DVR_SHOWSTRINGINFO _showstringinfo = new NET_DVR_SHOWSTRINGINFO();

NET_DVR_SHOWSTRING _showstring = new NET_DVR_SHOWSTRING();

string strTT = "我是来测试的!";

_showstring.dwSize = 1;
_showstring.struStringInfo = _showstringinfo;
_showstring.struStringInfo.dwShowString = 1;
_showstring.struStringInfo.sString = strTT;
_showstring.struStringInfo.wStringSize = strTT.Length;
_showstring.struStringInfo.wShowStringTopLeftX = 100;
_showstring.struStringInfo.wShowStringTopLeftY = 100;

int iSize= Marshal.SizeOf(_showstring);

bool bac = NET_DVR_SetDVRConfig(iLoginRef, 131, 0, _showstring, iSize);
if (bac == false)
{
MessageBox.Show("失败");
}
}




不知道为什么,一直失败,做过的帮个忙看看!!




/*****************************DS-6001D/F(end)***************************/

//单字符参数(子结构)
typedef struct
{
WORD wShowString; // 预览的图象上是否显示字符,0-不显示,1-显示 区域大小704*576,单个字符的大小为32*32
WORD wStringSize; /* 该行字符的长度,不能大于44个字符 */
WORD wShowStringTopLeftX; /* 字符显示位置的x坐标 */
WORD wShowStringTopLeftY; /* 字符名称显示位置的y坐标 */
char sString[44]; /* 要显示的字符内容 */
}NET_DVR_SHOWSTRINGINFO, *LPNET_DVR_SHOWSTRINGINFO;

//叠加字符(9000扩展)
typedef struct
{
DWORD dwSize;
NET_DVR_SHOWSTRINGINFO struStringInfo[MAX_STRINGNUM_V30]; /* 要显示的字符内容 */
}NET_DVR_SHOWSTRING_V30, *LPNET_DVR_SHOWSTRING_V30;

//叠加字符扩展(8条字符)
typedef struct
{
DWORD dwSize;
NET_DVR_SHOWSTRINGINFO struStringInfo[MAX_STRINGNUM_EX]; /* 要显示的字符内容 */
}NET_DVR_SHOWSTRING_EX, *LPNET_DVR_SHOWSTRING_EX;

//叠加字符
typedef struct
{
DWORD dwSize;
NET_DVR_SHOWSTRINGINFO struStringInfo[MAX_STRINGNUM]; /* 要显示的字符内容 */
}NET_DVR_SHOWSTRING, *LPNET_DVR_SHOWSTRING;

/*********************************************************
Function: OnBnClickedBtnStringOk
Desc: finish text overlay settings
Input:
Output:
Return:
**********************************************************/
void CDlgRemoteShowString::OnBnClickedBtnStringOk()
{
UpdateData(TRUE);
char szLan[128] = {0};
int i = m_comboShowArea.GetCurSel();
m_struShowString.struStringInfo[i].wShowString = (WORD)m_bChkShow;
memcpy(m_struShowString.struStringInfo[i].sString, m_csString, 44);
m_struShowString.struStringInfo[i].wStringSize = (WORD)strlen(m_csString);
m_struShowString.struStringInfo[i].wShowStringTopLeftX = (WORD)m_iStringX;
m_struShowString.struStringInfo[i].wShowStringTopLeftY = (WORD)m_iStringY;
if (!NET_DVR_SetDVRConfig(m_lLoginID, NET_DVR_SET_SHOWSTRING_V30, m_iChanShowNum, &m_struShowString, sizeof(NET_DVR_SHOWSTRING_V30)))
{
g_pMainDlg->AddLog(g_pMainDlg->m_iCurDeviceIndex, OPERATION_FAIL_T, "NET_DVR_SET_SHOWSTRING_V30");
g_StringLanType(szLan, "设置字符参数失败", "Failure to set character parameters");
AfxMessageBox(szLan);
return ;
}
g_pMainDlg->AddLog(g_pMainDlg->m_iCurDeviceIndex, OPERATION_SUCC_T, "NET_DVR_SET_SHOWSTRING_V30");
}

...全文
805 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Softwaring 2012-03-24
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 pfworld 的回复:]

自己解决!!谢谢帮忙UP的朋友!!
[/Quote]

解决的话分享一下下
Softwaring 2012-03-24
  • 打赏
  • 举报
回复 2
解决了, 分享一下:

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct NET_DVR_SHOWSTRING_V30
{
/// <summary>
/// 结构体大小
/// </summary>
public int dwSize;
/// <summary>
/// 要显示的字符内容
/// </summary>
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 8)]
public NET_DVR_SHOWSTRINGINFO[] struStringInfo;
};

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct NET_DVR_SHOWSTRINGINFO
{
/// <summary>
/// 预览的图象上是否显示字符,0-不显示,1-显示 区域大小704*576,单个字符的大小为32*32
/// </summary>
public ushort wShowString;
/// <summary>
/// 该行字符的长度,不能大于44个字符
/// </summary>
public ushort wStringSize;
/// <summary>
/// 字符显示位置的x坐标
/// </summary>
public ushort wShowStringTopLeftX;
/// <summary>
/// 字符名称显示位置的y坐标
/// </summary>
public ushort wShowStringTopLeftY;
/// <summary>
/// 要显示的字符内容
/// </summary>
[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);



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(UserID, 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 = "Yan";
ShowStruct.struStringInfo[0].wShowString = 1;
ShowStruct.struStringInfo[0].wShowStringTopLeftX = 10;
ShowStruct.struStringInfo[0].wShowStringTopLeftY = 10;
ShowStruct.struStringInfo[0].wStringSize = 3;

IntPtr ptrNow = Marshal.AllocCoTaskMem(Marshal.SizeOf(ShowStruct));
Marshal.StructureToPtr(ShowStruct, ptrNow, false);
err = NET_DVR_SetDVRConfig(UserID, 1031, 1, ptrNow, Marshal.SizeOf(ShowStruct));

return err;
lijianli9 2011-12-08
  • 打赏
  • 举报
回复
看你的连接的是硬盘录像机,还是摄像头,有可能硬盘录像机不支持。
im_DD 2011-07-13
  • 打赏
  • 举报
回复
今天 又让我给遇到到,怎么整??
pipi04132417 2011-02-09
  • 打赏
  • 举报
回复
小弟同样遇到问题,不知道可否指点一下?
pfworld 2010-07-01
  • 打赏
  • 举报
回复
自己解决!!谢谢帮忙UP的朋友!!
pfworld 2010-06-27
  • 打赏
  • 举报
回复
希望友情多一点!!希望友情多一点!!希望友情多一点!!
pfworld 2010-06-25
  • 打赏
  • 举报
回复
希望友情多一点!!
pfworld 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 oraclefans999 的回复:]
友情帮顶...
[/Quote]

希望友情多一点!!
pointma 2010-06-23
  • 打赏
  • 举报
回复
帮顶一下
pfworld 2010-06-23
  • 打赏
  • 举报
回复
顶一下!免得沉到沟了!!
oracleFans999 2010-06-23
  • 打赏
  • 举报
回复
友情帮顶...
pfworld 2010-06-23
  • 打赏
  • 举报
回复
UP 一下!!寻求帮助和帮顶!
zhanggd614 2010-06-22
  • 打赏
  • 举报
回复
帮你顶
pfworld 2010-06-22
  • 打赏
  • 举报
回复
UP 又分!!帮忙呀!
pfworld 2010-06-22
  • 打赏
  • 举报
回复
//叠加字符
typedef struct
{
DWORD dwSize;
NET_DVR_SHOWSTRINGINFO struStringInfo[MAX_STRINGNUM]; /* 要显示的字符内容 */
}NET_DVR_SHOWSTRING, *LPNET_DVR_SHOWSTRING;


这个在C#中如何初始化,并且定义呢??
pfworld 2010-06-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhanggd614 的回复:]
int iSize= Marshal.SizeOf(_showstring); 转换问题
[/Quote]


目前就这个问题难搞!
vip__888 2010-06-22
  • 打赏
  • 举报
回复
有点难度啊。
zhanggd614 2010-06-22
  • 打赏
  • 举报
回复
int iSize= Marshal.SizeOf(_showstring); 转换问题

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧