Main Site Documentation

Restarting Camera.StartStreamingBitmaps after Camera.PictureCaptured


#1

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?


#2

Isn’t that essentially the same thing the Flip Book Maker project does? You may want to take a browse through it and see if anything is different.


#3

Thanks Ian. They do stop and start streaming but they do not perform a capture in between. I do, so their code doesn’t work for me. They have no issues starting and stopping using camera.StopStreamingBitmaps and camera.StartStreamingBitmaps which is where I see the exception.


#4

Is there a solution for that bug?
Thx dutzend