110,533
社区成员
发帖
与我相关
我的任务
分享
[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");
}
[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;