Main Site Documentation

ArgumentException several seconds after camera.TakePicture() is called


Using a Camera Module (CMRAU-GM-283), Button Module, USB Client DP Module, and a FEZ Spider running all the latest GHI-recommended versions, I have a simple Gadgeteer application that attempts to take a picture when the button is pressed. The button down event just checks to see if camera.RameraReady, and if so, it calls camera.TakePicture(). I have a handler wired to the camera.PictureCaptured event, but that never fires. I receive the button.ButtonPressed event, and about seven seconds after TakePicture() is called, I get the following:

#### Exception System.ArgumentException - 0xfd000000 (5) ####
#### Message: 
#### GHI.Utilities.Bitmaps::NativeConvertToFile [IP: 0000] ####
#### GHI.Utilities.Bitmaps::ConvertToFile [IP: 003e] ####
#### GHI.Utilities.Bitmaps::ConvertToFile [IP: 0021] ####
#### Gadgeteer.Modules.GHIElectronics.Camera::DoWork [IP: 007e] ####

This happens 100% of the time, and I’ve tried it with two different camera modules (both the CMRAU-GM-283 model from GHI). I have confirmed that the camera it is always plugged into an H socket (socket 3), and have tried it with and without an external power supply. I have also tried three different Gadgeteer cables. The result is always the same exception.

The application is a slightly modified version of the very simple code presented in “Getting Started with .NET Gadgeteer” pp. 24-25. The only difference is that (a) I’m using the ButtonPressed event instead of a timer event to trigger taking a picture, and (b) the PictureCaptured event handler is just a Debug.Print (which never gets called).

Any thoughts on what I might be doing wrong?



@ kgcode - This is a known issue in the current SDK. The only workarounds are to go back to R4 or use a software bitmap conversion function which severely degrades performance. has more information.


@ John -

Thanks much. Somehow missed that thread in my search.

I’m taking the BitmapStreamed/StopStreaming approach for now. So, I’m doing a StartStreaming in the button pressed handler, and a StopStreaming in the BitmapStreamed handler.

There is a delay of between 2 and 14 seconds (varies with each button press) between the time StartStreaming is called and the BitmapStreamed event arrives. The application doesn’t do anything else. In fact, it doesn’t even display a picture right now…it just does a debug print that a picture arrived. (I’m incrementally developing a series of examples for an upcoming presentation…hence the extreme simplicity and lack of functionality in the code.)

Is this delay normal behavior for this camera module? If it’s normal, that’s fine. But if not, I’d like to understand how to get around it.

To show how bare-bones this is, here’s the code:

    public partial class Program
        void ProgramStarted()
            Debug.Print("Program Started");
            button.Mode = Button.LedMode.OnWhileReleased;
            button.ButtonPressed += button_ButtonPressed;
            camera.CameraConnected += camera_CameraConnected;
            camera.CameraDisconnected += camera_CameraDisconnected;
            camera.BitmapStreamed += camera_BitmapStreamed;

        void camera_CameraDisconnected(Camera sender, EventArgs e)
            Debug.Print("Camera disconnected.");

        void camera_BitmapStreamed(Camera sender, Bitmap e)
            Debug.Print("Bitmap received.");

        void camera_CameraConnected(Camera sender, EventArgs e)
            Debug.Print("Camera connected.");
            camera.CurrentPictureResolution = Camera.PictureResolution.Resolution320x240;

        void button_ButtonPressed(Button sender, Button.ButtonState state)
            if (state == Button.ButtonState.Pressed)
                Debug.Print("Button pressed.");

                if (camera.CameraReady)
                    Debug.Print("Start streaming...");


@ kgcode - A delay like that is expected on the Spider. You can try streaming lower resolutions to see if the performance improves.


@ John -

Thanks. Will do.


@ John -

Using the workaround, I still need to save the file to an SDCard in a valid BMP format (openable on a PC), so I tried Bitmaps.ConvertToFile, but that sent me down the same code path that leads to an exception in NativeConvertToFile.

I hunted around for Util.BitmapToBMPFile, which is mentioned in the “Getting Started with .NET Gadgeteer” book and in several forum posts, but I wasn’t able to find it. I suppose it might also end up going down the same code path.

Could you point me to source code for a working Bitmaps.ConvertToFile (or equivalent), so that I can write files that are valid BMP files?



I think post #5 in the previous thread on this gave a workaround that, while in managed code and therefore much slower, should have given you the Convert() method ?


@ Brett -

Oops. I see that now. Thanks.

Looks like all I needed was the ConvertToFile method listed there, and just call that directly with the appropriate output buffer size. Works perfectly…the BMP files are now readable.

Thanks again.