使用海康摄像头SDK里的DrawFun回调函数实现在实时浏览的摄像头界面上绘制图形。
回调函数定义:
public CHCNetSDK.DRAWFUN DrawFun = null;
在播放浏览函数内对播放句柄进行定义,注意第三个输入量为null
m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
当句柄m_lRealHandle为非负时,即预览成功后注册绘图回调函数
DrawFun = new CHCNetSDK.DRAWFUN(DrawFunCallBack);
bool b = CHCNetSDK.NET_DVR_RigisterDrawFun(m_lRealHandle, DrawFun, 0);
之后具体的绘画内容在回调函数DrawFunCallBack画就可以了,比如:
public void DrawFunCallBack(int lRealHandle, IntPtr hDc, uint dwUser)
{
Graphics g = Graphics.FromHdc(hDc);
if (null == g)
return;
int Wid = _wnd.Width;
int Hig = _wnd.Height;
Pen pen = new Pen(Color.Red, 1);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
pen.DashPattern = new float[] { 5, 5 };
Point point1 = new Point(Wid / 2, 0);
Point point2 = new Point(Wid / 2, Hig);
Point point3 = new Point(0, Hig / 2);
Point point4 = new Point(Wid, Hig / 2);
Rectangle rect = new Rectangle(Wid / 2 - Hig / 4, Hig / 4, Hig / 2, Hig / 2);
g.DrawLine(pen, point1, point2);
g.DrawLine(pen, point3, point4);
g.DrawEllipse(pen, rect);
pen.Dispose();
g.Dispose();
}
效果图
_wnd是类里接收到的Picturebox浏览窗口。
具体的写了个.cs可以使用PictureBox浏览视频并画图标注
加载命名空间后使用
PlayVideo play1 = new PlayVideo();
string IP1 = "192.168.1.13";
string User = "admin";
string Pw = "abcd1234";
play1.IP = IP1;
play1.User = User;
play1.Pw = Pw;
play1.Wnd = RealPlayWnd1;//PicTureBox
play1.masking = true;//启动绘图回调函数
play1.Login();
play1.Preview();