c#未处理nullreferen未将对象引用设置到对象的实例。 PictureBox1.Image = Ima

.Net技术 码拜 8年前 (2016-05-11) 2235次浏览
c#未处理nullreferen未将对象引用设置到对象的实例。 PictureBox1.Image = Imac#未处理nullreferen未将对象引用设置到对象的实例。 PictureBox1.Image = Imausing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.GPU;
using Emgu.CV.ML;
using Emgu.CV.OpenCL;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using Emgu.CV.DebuggerVisualizers;
using ZedGraph;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Emgu.CV.CvEnum;
namespace Case03_6
{
public partial class Form1 : Form
{
public Emgu.CV.Structure.MCvScalar t2;
public double data;
public Bitmap dast1;
public string dast2;
public Form1()
{
InitializeComponent();
}
private Capture capture;     //从摄像头获取ok

private bool captureInProgress;//检查摄像头
private void ProcessFrame(object sender, EventArgs arg)
{
;
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();

PictureBox1.Image = ImageFrame.ToBitmap();
ImageFrame.Save(@”F:\LightFlow_Finally(6,12)\AVI_LightFlow\Pic_Save\a1.jpg”);//储存图
}
private void btnStart_Click(object sender, EventArgs e)//视频开始工作
{
//#假如摄像头没建立现在建一个
if (capture == null)
{
try
{
capture = new Capture(); }

catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
//#建立完毕
if (capture != null)
{
if (captureInProgress)
{
btnStart.Text = “Stop”;
Application.Idle -= new EventHandler(ProcessFrame);
}
else
{

btnStart.Text = “Start”;
Application.Idle += new EventHandler(ProcessFrame);
}
captureInProgress = !captureInProgress;
}
ReleaseData();
}

private void ReleaseData()//释放函数
{
if (capture != null)
capture.Dispose();
}
这个问题怎么解决 求高手帮帮
PictureBox1.Image = ImageFrame.ToBitmap();这一行出错c#未处理nullreferenceexception
未将对象引用设置到对象的实例。  这个好像需要实例化 但是不知从何下手

解决方案

20

1,估计是上句中给ImageFrame赋值,返回的是null,确定queryFrame方法能否正确
2,确定PictureBox1已经实例化

20

判断假如为空就不往下走了

20

贴出全部代码,尤其QueryFrame();

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c#未处理nullreferen未将对象引用设置到对象的实例。 PictureBox1.Image = Ima
喜欢 (0)
[1034331897@qq.com]
分享 (0)