我有一个 .Net Gadgeteer 相机应用程序,可将位图从相机流式传输到屏幕。按一下按钮,它会停止从相机流式传输位图,拍照,将其写入 SD 卡,然后重新启动流式传输。这是代码的简化版本(没有保存到 SD 卡的东西):
using Microsoft.SPOT;
using GT = Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;
namespace SimpleStopStreamingApp
{
public partial class Program
{
void ProgramStarted()
{
camera.CameraConnected += new Camera.CameraConnectedEventHandler(camera_CameraConnected);
camera.BitmapStreamed += new Camera.BitmapStreamedEventHandler(camera_BitmapStreamed);
camera.PictureCaptured += new Camera.PictureCapturedEventHandler(camera_PictureCaptured);
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
}
void camera_CameraConnected(Camera sender)
{
camera.StartStreamingBitmaps(new Bitmap(camera.CurrentPictureResolution.Width, camera.CurrentPictureResolution.Height));
}
void camera_BitmapStreamed(Camera sender, Bitmap bitmap)
{
display_T35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
}
void button_ButtonPressed(Button sender, Button.ButtonState state)
{
camera.StopStreamingBitmaps();
camera.TakePicture();
}
void camera_PictureCaptured(Camera sender, GT.Picture picture)
{
camera.StartStreamingBitmaps(new Bitmap(camera.CurrentPictureResolution.Width, camera.CurrentPictureResolution.Height));
}
}
}
但是,当我尝试重新启动流式传输(在 PictureCaptured 事件处理程序中)时,我得到了异常。
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHI.Premium.USBHost.USBH_Webcam::StartStreaming_Internal [IP: 0000] ####
#### GHI.Premium.USBHost.USBH_Webcam::StartStreaming [IP: 0005] ####
#### Gadgeteer.Modules.GHIElectronics.Camera::StartStreamingBitmaps [IP: 007e] ####
#### Gadgeteer.Modules.GHIElectronics.Camera::OnPictureCapturedEvent [IP: 0037] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type 'System.Exception' occurred in GHI.Premium.USBHost.dll
Error invoking method "Gadgeteer.Modules.GHIElectronics.Camera" (check arguments to Program.BeginInvoke are correct)
(注意,如果我将位图存储为实例变量并将其传递给对 StartStreamingBitmaps 的两个调用,而不是每次都创建一个新的位图,我会得到同样的异常。)
这是怎么回事?应该如何停止相机流式传输以捕获和图像,然后重新启动它流式传输?