二、截圖
VC++ Code:
////////////////////////////////////////////////////////////////// //Function:The call back funtion for capture image! ///////////////////////////////////////////////////////////////// void CALLBACK DisplayCBFun(long nPort,\ char * pBuf,long nSize,\ long nWidth,long nHeight,\ long nStamp,long nType,long nReceaved) { if(!g_bCapPic) return; CString csFile; csFile.Format("capture%02d.bmp",pic); /* switch(nType) { case T_UYVY: csFile="uyvy.bmp"; break; case T_YV12: csFile="yv12.bmp"; break; case T_RGB32: csFile="rgb.bmp"; break; default: return ; }*/ //Note:this funtion is slow,so if you want to save as a .bmp file,don't call! if(!Hik_PLayM4_ConvertToBmpFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength()))) { CString csErr; csErr.Format("Convert to bmp faild(%d).",Hik_PlayM4_GetLastError(nPort)); AfxMessageBox(csErr); } pic++; g_bCapPic=FALSE; }
C# Code:
DisplayCBFun DisCB;
/// <summary>
/// 截圖
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCapImage_Click(object sender, EventArgs e)
{
DisCB = new DisplayCBFun(DisplayCBFun);
HikPlayer.Hik_PlayM4_SetDisplayCallBack(PORT, DisCB);
}
/// <summary>
/// 截圖回調函數
/// </summary>
/// <param name="nPort"></param>
/// <param name="pBuf"></param>
/// <param name="nSize"></param>
/// <param name="nWidth"></param>
/// <param name="nHeight"></param>
/// <param name="nStamp"></param>
/// <param name="nType"></param>
/// <param name="nReceaved"></param>
public void DisplayCBFun(int nPort, IntPtr pBuf, int nSize, int nWidth, int nHeight, int nStamp, int nType, int nReceaved)
{
if (HikPlayer.Hik_PLayM4_ConvertToBmpFile(pBuf, nSize, nWidth, nHeight, nType, string.Format("C:\\capture{0}.bmp", nPort)))
{
MessageBox.Show("轉換bmp失敗!");
}
//停止回調
HikPlayer.Hik_PlayM4_SetDisplayCallBack(PORT, null);
}
代碼說明:
1. 這裡和源代碼有點出入,他用的是g_bCapPic變量來控制是否捕獲圖片,我用的是設置委托實例和null來達到。API說明:設置抓圖回調 函數;注意要盡快返回,如果要停止回調,可以把回調函數指針DisplayCBFun設為NULL。
結束
現在在做語音部分,受阻中...