这一阵一直在做海康威视的摄像头的调试工作,根据官方给的Demo,这里做了一些修改,删掉了云台的功能,添加了显示抓取图片的模块,这里话不多说,先上程序运行结果:
如果你需要的是这样的程序,那么你可以下载下来看一看,Demo是基于VS2013(X86 的SDK)开发的,加载了海康威视最新的SDK
这里大家仅仅需要执行导入文件的那部分内容就可以了,至于官方Demo中的那个问题,我已经在上传的程序中进行了修正
然后附上抓图显示的核心代码:
void CRealPlayDlg::OnButtonCapture()
{
if (m_lPlayHandle == -1)
{
MessageBox("请先选择一个通道播放");
return;
}
UpdateData(TRUE);
char PicName[256] = { 0 };
int iPicType = m_coPicType.GetCurSel();
if (0 == iPicType) //bmp
{
CTime CurTime = CTime::GetCurrentTime();;
sprintf(PicName, "%04d%02d%02d%02d%02d%02d_ch%02d.bmp", CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(), \
CurTime.GetHour(), CurTime.GetMinute(), CurTime.GetSecond(), m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex);
if (NET_DVR_CapturePicture(m_lPlayHandle, PicName))
{
MessageBox("抓图成功!");
CString PIC = PicName;
CImage image;
int cx, cy;
CRect rect;
//根据路径载入图片
//char strPicPath[] = PicName;
image.Load(PIC);
//获取图片的宽 高
cx = image.GetWidth();
cy = image.GetHeight();
CWnd *pWnd = NULL;
pWnd = GetDlgItem(IDC_IMG);//获取控件句柄
//获取Picture Control控件的客户区
pWnd->GetClientRect(&rect);
CDC *pDc = NULL;
pDc = pWnd->GetDC();//获取picture control的DC
//设置指定设备环境中的位图拉伸模式
int ModeOld = SetStretchBltMode(pDc->m_hDC, STRETCH_HALFTONE);
//从源矩形中复制一个位图到目标矩形,按目标设备设置的模式进行图像的拉伸或压缩
image.StretchBlt(pDc->m_hDC, rect, SRCCOPY);
SetStretchBltMode(pDc->m_hDC, ModeOld);
ReleaseDC(pDc);
}
}
else if (1 == iPicType) //jgp
{
CTime CurTime = CTime::GetCurrentTime();;
sprintf(PicName, "%04d%02d%02d%02d%02d%02d_ch%02d.jpg", CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(), \
CurTime.GetHour(), CurTime.GetMinute(), CurTime.GetSecond(), m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex);
//组建jpg结构
NET_DVR_JPEGPARA JpgPara = { 0 };
JpgPara.wPicSize = (WORD)m_coJpgSize.GetCurSel();
JpgPara.wPicQuality = (WORD)m_coJpgQuality.GetCurSel();
LONG iCurChan = m_struDeviceInfo.struChanInfo[GetCurChanIndex()].iChanIndex;
if (NET_DVR_CaptureJPEGPicture(m_struDeviceInfo.lLoginID, iCurChan, &JpgPara, PicName))
{
MessageBox("抓图成功");
CString PIC = PicName;
CImage image;
int cx, cy;
CRect rect;
//根据路径载入图片
//char strPicPath[] = PicName;
image.Load(PIC);
//获取图片的宽 高
cx = image.GetWidth();
cy = image.GetHeight();
CWnd *pWnd = NULL;
pWnd = GetDlgItem(IDC_IMG);//获取控件句柄
//获取Picture Control控件的客户区
pWnd->GetClientRect(&rect);
CDC *pDc = NULL;
pDc = pWnd->GetDC();//获取picture control的DC
//设置指定设备环境中的位图拉伸模式
int ModeOld = SetStretchBltMode(pDc->m_hDC, STRETCH_HALFTONE);
//从源矩形中复制一个位图到目标矩形,按目标设备设置的模式进行图像的拉伸或压缩
image.StretchBlt(pDc->m_hDC, rect, SRCCOPY);
SetStretchBltMode(pDc->m_hDC, ModeOld);
ReleaseDC(pDc);
}
}
return;
}