函数
NET_DVR_SHOWSTRING_V30 // OSD信息集
NET_DVR_GetDVRConfig// 获取
NET_DVR_SetDVRConfig// 设置
添加
/**
* 设置 OSD 字符叠加参数
*
* @param iUserID loginId
* @param iChan 通道号
* @param contents 内容
*/
public static void SetOSDString(int iUserID, int iChan, String[] contents) throws UnsupportedEncodingException {
if (iUserID < 0) return;
if (null == contents || contents.length <= 0) return;
NET_DVR_SHOWSTRING_V30 cfg = new NET_DVR_SHOWSTRING_V30();
if (!HCNetSDK.getInstance().NET_DVR_GetDVRConfig(iUserID, HCNetSDK.NET_DVR_GET_SHOWSTRING_V30, iChan, cfg)) {
System.out.println("NET_DVR_GET_SHOWSTRING_V30 faild!" + " err: " + HCNetSDK.getInstance().NET_DVR_GetLastError());
return;
} else {
System.out.println("NET_DVR_GET_SHOWSTRING_V30 succ!");
}
int iIndex = 0;
for (int i = 0; i < contents.length; i++) {
if ("".equals(contents[i]))
continue;
if (iIndex >= cfg.struStringInfo.length)//防止超限
break;
byte[] tempBytes = new byte[128];
byte[] osd = contents[i].getBytes("GBK");
System.arraycopy(osd, 0, tempBytes, 0, osd.length);
cfg.struStringInfo[iIndex].wShowString = 1;//1为显示,0为不显示
cfg.struStringInfo[iIndex].sString = tempBytes;//叠加的字符串
cfg.struStringInfo[iIndex].wStringSize = osd.length;//字符串大小
// 显示范围704*576
cfg.struStringInfo[iIndex].wShowStringTopLeftX = 550;//坐标x
cfg.struStringInfo[iIndex].wShowStringTopLeftY = 50 + (iIndex * 38);//坐标y
iIndex++;
}
HCNetSDK.getInstance().NET_DVR_SetDVRConfig(iUserID, HCNetSDK.NET_DVR_SET_SHOWSTRING_V30, iChan, cfg);
}
获取
/**
* 获取 OSD 字符叠加参数
*
* @param iUserID loginId
* @param iChan 通道号
*/
public static String[] GetOSDString(int iUserID, int iChan) throws UnsupportedEncodingException {
if (iUserID < 0) return null;
NET_DVR_SHOWSTRING_V30 cfg = new NET_DVR_SHOWSTRING_V30();
if (!HCNetSDK.getInstance().NET_DVR_GetDVRConfig(iUserID, HCNetSDK.NET_DVR_GET_SHOWSTRING_V30, iChan, cfg)) {
System.out.println("NET_DVR_GET_SHOWSTRING_V30 faild!" + " err: " + HCNetSDK.getInstance().NET_DVR_GetLastError());
return null;
}
System.out.println("NET_DVR_GET_SHOWSTRING_V30 succ!");
String[] OSDStrings = new String[cfg.struStringInfo.length];
for (int i = 0; i < cfg.struStringInfo.length; i++) {
if (cfg.struStringInfo[i].wShowString == 1) {
OSDStrings[i] = new String(cfg.struStringInfo[i].sString, "GBK");
}
}
return OSDStrings;
}
清除
/**
* 清除OSD
*
* @param iUserID loginId
* @param iChan 通道号
*/
public static void ClearOSD(int iUserID, int iChan) {
if (iUserID < 0) return;
NET_DVR_SHOWSTRING_V30 cfg = new NET_DVR_SHOWSTRING_V30();
if (!HCNetSDK.getInstance().NET_DVR_GetDVRConfig(iUserID, HCNetSDK.NET_DVR_GET_SHOWSTRING_V30, iChan, cfg)) {
System.out.println("NET_DVR_GET_SHOWSTRING_V30 faild!" + " err: " + HCNetSDK.getInstance().NET_DVR_GetLastError());
return;
} else {
System.out.println("NET_DVR_GET_SHOWSTRING_V30 succ!");
}
for (int i = 0; i < cfg.struStringInfo.length; i++) {
cfg.struStringInfo[i].wShowString = 0;//1为显示,0为不显示
}
HCNetSDK.getInstance().NET_DVR_SetDVRConfig(iUserID, HCNetSDK.NET_DVR_SET_SHOWSTRING_V30, iChan, cfg);
}
使用及注意
- 单行字符的长度,不能大于44 个字符
- 获取字符时,注意空字符及编解码问题,获取到的字符集是填满的
- 注意判断边界,防止越界异常
添加OSD
String[] content = new String[3];
content[0] = "test1: 123";
content[1] = "测试2: 我真帅";
content[2] = "it's three";
try {
DevOSDConfig.SetOSDString(VideoFragment.m_iUserID, 1, content);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
获取OSD
try {
String[] strings = DevOSDConfig.GetOSDString(VideoFragment.m_iUserID, 1);
if (strings != null && strings.length > 0)
for (String string : strings) {
if (string != null && !string.isEmpty()) {
L.e(string.trim());
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
清除OSD
DevOSDConfig.ClearOSD(VideoFragment.m_iUserID, 1);
网友评论