C#读取摄像头数据error:未将对象引用设置到对象的实例解决方案
C#读取摄像头数据error:未将对象引用设置到对象的实例
我的程序是希望得到摄像头的数据,并显示,但是总是提示未将对象设置到对象的实例,自己查了下网上的说法,说是有对象为null,然后检查了下自己的程序,还是没发现哪儿错了,求高手帮忙~感激~
代码如下
------解决思路----------------------
要看MfcDllEncapsulater是怎么实现的了,它是不是只能控制某种专用的硬件。
------解决思路----------------------
这种专用的摄像头dll,只有用过的人能给你建议。
------解决思路----------------------
摄像头是什么牌子的,上网找他们官网,官网上有技术支持电话
------解决思路----------------------
上官网,看有没有demo可以下载,一般都会有
然后根据demo修改修改
我的程序是希望得到摄像头的数据,并显示,但是总是提示未将对象设置到对象的实例,自己查了下网上的说法,说是有对象为null,然后检查了下自己的程序,还是没发现哪儿错了,求高手帮忙~感激~
代码如下
//回调函数;
public static bool callbackData(int index, int mode, byte[] data, int len, int w, int h)
{
if (data == null)
{
return false;
}
int nRet = 0;
nRet = MfcDllEncapsulater.WP_IPC_DisplayFrame(index, data);
if (WP_IPC_NOERROR != nRet)
{
string Error = "DisplayFrame Failed: " + nRet.ToString();
return false;
}
return true;
}
public static bool callbackEvent(int index, int type)
{
return true;
}
#region 线程处理
//连接视频通道;
public void Connect(IntPtr wndHandle, int wndWidth, int wndHeight, int screenId)
{
this.hwnd = wndHandle;
this.wndWidth = wndWidth;
this.wndHeight = wndHeight;
this.screenId = screenId;
if (connectState != ConnectState.Connected || connectState != ConnectState.Connecting)
{
if (channelConnectThread == null)
{
channelConnectThread = new Thread(new ThreadStart(DoChannelConnect));
channelConnectThread.Name = string.Format("ChannelConnect_{0}", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
channelConnectThread.IsBackground = true;
}
channelConnectThread.Start();
}
}
private void DoChannelConnect()
{
Mutex mutex = new Mutex();
connectState = ConnectState.Connecting;
int nRet = 0;
if (isSdkInitilized == false)
{
nRet = MfcDllEncapsulater.WP_IPC_Init();
if (WP_IPC_NOERROR != nRet)
{
connectState = ConnectState.Disconnected;
MfcDllEncapsulater.WP_IPC_Cleanup();
return;
}
isSdkInitilized = true;
}
//初始化多D3D设备;
nRet = MfcDllEncapsulater.WP_InitDirect3D(hwnd);
if (WP_IPC_NOERROR != nRet)
{
connectState = ConnectState.Disconnected;
MfcDllEncapsulater.WP_DestroyDirect3D(hwnd);
return;
}
//设置显示的最大路数;
nRet = MfcDllEncapsulater.WP_SetShowMode(6);
if (WP_IPC_NOERROR != nRet)
{
connectState = ConnectState.Disconnected;
string strError = "SetShowMode Failed:" + nRet.ToString();
return;
}
//连接摄像机;
handle = MfcDllEncapsulater.WP_IPC_Login(ipAddress, dataFormat);
if (handle < 0)
{
strError = "Login Failed!";
connectState = ConnectState.Disconnected;
return;
}
CAMERAINFO cameraInfo = new CAMERAINFO();
nRet = MfcDllEncapsulater.WP_IPC_GetCameraInfo(handle, ref cameraInfo);
//设置回调函数;
//获取摄像机的连接状态;
MfcDllEncapsulater.EventCallBack eventCallback = new MfcDllEncapsulater.EventCallBack(callbackEvent);
nRet = MfcDllEncapsulater.WP_IPC_SetEventCallBack(eventCallback);
if (WP_IPC_NOERROR != nRet)
{
strError = "SetEventCallBack Failed: " + nRet.ToString();
connectState = ConnectState.Disconnected;
return;
}
if (STREAM_HD == streamType)
{
width = cameraInfo.nHDWidth;
height = cameraInfo.nHDHeight;
}
else if (STREAM_CIF == streamType)
{
width = cameraInfo.nCIFWidth;
height = cameraInfo.nCIFHeight;
}
//创建显示区域;
nRet = MfcDllEncapsulater.WP_IPC_CreateOneSurface(screenId, this.wndWidth, this.wndHeight, (int)DATAFormat.DATA_FMT_BGRA);
if (WP_IPC_NOERROR != nRet)
{
strError = "CreateOneSurface Failed: " + nRet.ToString();
connectState = ConnectState.Disconnected;
MfcDllEncapsulater.WP_IPC_FreeOneSurface(screenId);
return;
}
//获取数据;
MfcDllEncapsulater.DataCallBack dataCallback = new MfcDllEncapsulater.DataCallBack(callbackData);
nRet = MfcDllEncapsulater.WP_IPC_SetDataCallBack(dataCallback);
if (WP_IPC_NOERROR != nRet)
{
strError = "SetDataCallBack Failed: " + nRet.ToString();
connectState = ConnectState.Disconnected;
return;
}
connectState = ConnectState.Connected;
}
}
------解决思路----------------------
要看MfcDllEncapsulater是怎么实现的了,它是不是只能控制某种专用的硬件。
------解决思路----------------------
这种专用的摄像头dll,只有用过的人能给你建议。
------解决思路----------------------
摄像头是什么牌子的,上网找他们官网,官网上有技术支持电话
------解决思路----------------------
上官网,看有没有demo可以下载,一般都会有
然后根据demo修改修改