I have a camera app that streams bitmaps from the camera to a screen. On the press of a button it stops streaming the bitmaps from the camera, takes a picture, writes it to SD card, and then restarts the streaming. Here’s a simplified version of the code (without the saving to SD card stuff):
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));
}
}
}
However when I try to restart the streaming (in the PictureCaptured event handler) I get the exception.
(N.B. I get this same exception if I store the bitmap as an instance variable and pass it in to both calls to StartStreamingBitmaps instead of creating a new Bitmap each time.)
What’s going on? How should one stop the camera streaming to capture and image and then restart it streaming?