111 / 5 000 Résultats de traduction I am trying to integrate a new camera into my software but I have an error message that I do not understand.
public void GetImageFromCamera()
{
lock (camera_stream_lock)
{
if (imageData != null)
{
//Stop and restart stopwatch to get average fps
fps_stopwatch.Stop();
TimeSpan ts = fps_stopwatch.Elapsed;
current_fps = 1000.0 / (double)ts.Milliseconds;
fps_stopwatch.Reset();
fps_stopwatch.Start();
//var bitmapData = new BitmapDataAcquisition();
var image = new Bitmap(imageData.Width, imageData.Height,imageData.PixelFormat);
var rect = new Rectangle(0, 0, width, height);
var data = image.LockBits(rect, ImageLockMode.ReadWrite, imageData.PixelFormat);
Marshal.Copy(imageData.Buffer, 0, data.Scan0, imageData.Buffer.Length);
image.UnlockBits(data);
current_image_count++;
Latest_image.Source = null;
//Convert and save latest image
Latest_image.Source = NativeMethods.ToBitmapSource(image);
}
if (recordCameraStream && Latest_image != null)
{
//recording_buffer.Add(Latest_image.Source);
}
}
I expect to receive video images from my camera but I have error messages error message: systemNullReferenceExeption:Object reference not set to an instance of an object
After debugging this is where the crash happen : Latest_image.Source = NativeMethods.ToBitmapSource(image);