??使用??禂z像頭采集圖像時(shí),需要在圖像上添加圖標(biāo)、文字等額外數(shù)據(jù)??蛇x擇使用SDK提供的NET_DVR_RigisterDrawFun()函數(shù)注冊繪圖回調(diào)函數(shù),使用NET_DVR_RealPlay_V40()的返回值(用于在DrawFun()函數(shù)中區(qū)分通道數(shù)據(jù))及DrawFun回調(diào)函數(shù)的指針進(jìn)行注冊。注意:使用DrawFun回調(diào)函數(shù),需要在調(diào)用NET_DVR_RealPlay_V40()時(shí)將第三個(gè)參數(shù)設(shè)置為null。
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)貴州免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了1000多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
class DeviceCamera : IDeviceCamera
{
private CameraInfo m_stCameraInfo;
private bool m_bInitSDK = false;
private Int32 m_lUserID = -1;
private Int32 m_lRealHandle = -1;
private CHCNetSDK.DRAWFUN cbDrawFun = null;
public override bool InitCamera( CameraInfo stInfo )
{
m_stCameraInfo = stInfo;
//
m_bInitSDK = CHCNetSDK.NET_DVR_Init();
if ( m_bInitSDK == false )
{
uint nError = CHCNetSDK.NET_DVR_GetLastError();
MessageBox.Show( "NET_DVR_Init error! ErrorCode: " + nError );
return false;
}
else
CHCNetSDK.NET_DVR_SetLogToFile( 3, "C:\\SdkLog\\", true );
CHCNetSDK.NET_DVR_SetConnectTime( 5000, 1 );
CHCNetSDK.NET_DVR_SetReconnect( 10000, 1 );
string DVRIPAddress = stInfo.strIP;
Int16 DVRPortNumber = stInfo.nPort;
string DVRUserName = stInfo.strUserName;
string DVRPassword = stInfo.strPassword;
CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
m_lUserID = CHCNetSDK.NET_DVR_Login_V30( DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo );
if ( m_lUserID < 0 )
{
MessageBox.Show( "登錄失?。? );
CHCNetSDK.NET_DVR_Cleanup();
return false;
}
//
CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO()
{
dwStreamType = 0,
dwLinkMode = 0,
bBlocked = true,
dwDisplayBufNum = 10,
};
//遍歷PictureBox列表
cbDrawFun = new CHCNetSDK.DRAWFUN( fDrawFun );
int nPicBoxSize = m_stCameraInfo.lstPicBoxHdc.Count() <= 4 ? m_stCameraInfo.lstPicBoxHdc.Count() : 4; //??禂z像頭模擬通道數(shù) <= 4
for ( int nPicBoxIndex = 1; nPicBoxIndex <= nPicBoxSize; nPicBoxIndex++ )
{
lpPreviewInfo.hPlayWnd = m_stCameraInfo.lstPicBoxHdc[ nPicBoxIndex - 1 ];
lpPreviewInfo.lChannel = nPicBoxIndex;
m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40( m_lUserID, ref lpPreviewInfo, null, new IntPtr() );
//設(shè)置異常消息回調(diào)函數(shù)
bool bRet = CHCNetSDK.NET_DVR_SetExceptionCallBack_V30( 0, lpPreviewInfo.hPlayWnd, new CHCNetSDK.EXCEPYIONCALLBACK( cbException ), new IntPtr() );
if ( !bRet )
MessageBox.Show( "設(shè)置異常消息回調(diào)函數(shù)失敗!" );
//注冊繪圖回調(diào)函數(shù)
bRet = CHCNetSDK.NET_DVR_RigisterDrawFun( m_lRealHandle, cbDrawFun, 0 );
if ( !bRet )
{
MessageBox.Show( "注冊繪圖回調(diào)函數(shù)失??!" );
return false;
}
}
return true;
}
private void fDrawFun( int lRealHandle, IntPtr hDC, uint dwUser )
{
try
{
Graphics pDC = Graphics.FromHdc( hDC );
if ( null == pDC )
return;
Brush hBrush = new SolidBrush( Color.Red );
Pen pen = new Pen( hBrush );
Rectangle rectTmp = new Rectangle( 100, 100, 100, 100 );
if( 0 == lRealHandle )//Channel 1
{
//Image
Bitmap img = new Bitmap( "../Images/NucSource.png" );
pDC.DrawImage( img, rectTmp );
//Text
string strText = "Novel RPS";
Font font = new Font( "黑體", 18, FontStyle.Italic | FontStyle.Bold );
Point pt = new Point( 100, 75 );
pDC.DrawString( strText, font, hBrush, pt );
//Rectangle
pDC.DrawRectangle( pen, rectTmp );
img.Dispose();
}
else if ( 1 == lRealHandle )//Channel 2
{
//Text
string strText = "Novel RPS";
Font font = new Font( "黑體", 18, FontStyle.Italic | FontStyle.Bold );
Point pt = new Point( 100, 75 );
pDC.DrawString( strText, font, hBrush, pt );
}
else if ( 2 == lRealHandle )//Channel 3
{
//Rectangle
pDC.DrawRectangle( pen, rectTmp );
}
else if ( 3 == lRealHandle )//Channel 4
{
//Image
Bitmap img = new Bitmap( "../Images/NucSource.png" );
pDC.DrawImage( img, rectTmp );
img.Dispose();
}
hBrush.Dispose();
pen.Dispose();
pDC.Dispose();
}
catch
{
uint nError = CHCNetSDK.NET_DVR_GetLastError();
if( nError != 0 )
MessageBox.Show( "cbDrawFun -- Catch Error Code: " + nError );
}
}
private void cbException( uint dwType, int lUserID, int lHandle, IntPtr pUser )
{
switch( dwType )
{
case 0x8000:
MessageBox.Show( "語音對講時(shí)網(wǎng)絡(luò)異常!" );
break;
case 0x8002:
MessageBox.Show( "報(bào)警上傳時(shí)網(wǎng)絡(luò)異常!" );
break;
case 0x8003:
MessageBox.Show( "網(wǎng)絡(luò)預(yù)覽時(shí)網(wǎng)絡(luò)異常!" );
break;
case 0x8004:
MessageBox.Show( "透明通道傳輸時(shí)網(wǎng)絡(luò)異常!" );
break;
case 0x8005:
MessageBox.Show( "預(yù)覽時(shí)重連!" );
break;
default:
MessageBox.Show( "攝像頭默認(rèn)異常!" );
break;
}
}
}
注:代碼中使用PictureBox顯示攝像頭圖像,故將其句柄設(shè)置給 lpPreviewInfo.hPlayWnd。
分享名稱:C#:使用??礢DK繪圖回調(diào)函數(shù)DrawFun()
文章分享:http://aaarwkj.com/article10/jejogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、建站公司、定制網(wǎng)站、云服務(wù)器、網(wǎng)站內(nèi)鏈、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)