抓拍
/// <summary>
/// 抓拍
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsButtonSnatch_Click(object sender, EventArgs e)
{
//检查用户登录状态
if (null == m_player.m_mainForm)
{
MessageBox.Show("请先登录!");
return;
}
//当前用户控制面板
selectedSubCtrl = m_player.m_mainForm.g_userCtrlList[m_player.m_mainForm.tabControl1.SelectedIndex];
if(null != selectedSubCtrl)
{
//当前播放通道
selectedPanel = selectedSubCtrl.imosPlayer.m_playerUnit[PlayerPanel.SelectedIndex];
}
//检查图片保存地址,默认为snatch
UInt32 ulRet = 0;
String picPath = LocalConfig.picSnatchLoc;
if (false == Directory.Exists(LocalConfig.picSnatchLoc))
{
Directory.CreateDirectory(LocalConfig.picSnatchLoc);
}
if(false ==LocalConfig.picSnatchLoc.EndsWith("\"))
{
//这里要给路径后添加""
picPath = LocalConfig.picSnatchLoc.Insert(LocalConfig.picSnatchLoc.Length, "\");
}
if(null != selectedPanel.channelCode)
{
//单次实时抓图
ulRet = IMOSSDK.IMOS_SnatchOnce(ref selectedSubCtrl.sdkManager.stLoginInfo.stUserLoginIDInfo,//用户登录标识
Encoding.Default.GetBytes(selectedPanel.channelCode),//频道号
Encoding.Default.GetBytes(picPath),//图像文件名
LocalConfig.picFormat);//图像格式
}
if (0 != ulRet)
{
log.Info("抓图失败,错误码为:" + ulRet.ToString());
MessageBox.Show("抓图失败,错误码为:" + ulRet.ToString());
}else
{
MessageBox.Show("抓图成功!图片保存在" + LocalConfig.picSnatchLoc);
}
}
调用sdk中的方法
/// <summary>
/// 单次实时抓拍
/// 图像文件名全部由用户指定
/// </summary>
/// <param name="stUserLoginInfo">用户标识信息</param>
/// <param name="szChannelCode">播放通道号</param>
/// <param name="szFileName">要保存的图像文件名</param>
/// <param name="ulPicFormat">图像格式</param>
/// <returns></returns>
[DllImport("xp_frame.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern UInt32 IMOS_SnatchOnceEx(ref USER_LOGIN_ID_INFO_S stUserLoginInfo, byte[] szChannelCode, byte[] szFileName, UInt32 ulPicFormat);
/// <summary>
/// 启动连续实时抓拍
/// </summary>
/// <param name="stUserLoginInfo">用户登录标识</param>
/// <param name="szChannelCode">播放通道号</param>
/// <param name="szFileName">图像文件存放路径,包括文件名(不带扩展名)</param>
/// <param name="ulPicFormat">图像文件的格式</param>
/// <param name="ulInterval">抓拍间隔,时间为毫秒</param>
/// <returns></returns>
[DllImport("xp_frame.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern UInt32 IMOS_StartSnatchSeries(ref USER_LOGIN_ID_INFO_S stUserLoginInfo, byte[] szChannelCode, byte[] szFileName, UInt32 ulPicFormat, UInt32 ulInterval);
/// <summary>
/// 停止连续实时抓拍
/// </summary>
/// <param name="stUserLoginInfo">用户标识</param>
/// <param name="szChannelCode">播放通道编码</param>
/// <returns></returns>
[DllImport("xp_frame.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern UInt32 IMOS_StopSnatchSeries(ref USER_LOGIN_ID_INFO_S stUserLoginInfo, byte[] szChannelCode);