I am trying to capture and save to SD card an image from the L2 Serial Camera.
I can capture the image and save on the SD without problems, but when I try to open the file on my PC, Windows says the file type is not recognized.
Below is my test program. The image appears in the upper corner of my LCD and the file is on the SD card. It is 76,800 bytes so there is something there. I am using a Raptor, NETMF 4.3 and Visual Studio 2012.
I have looked on the forums and code share.
I found [quote]Serial Camera L2 Module take single image and save to microSD[/quote] from which I got the basic code.
I also found [quote]Webserver displaying picture captured when button is pressed[/quote]. I could not get it to work (black image). Also did not understand why it used a DrawImage method instead of just calling GetImage, after apparently getting and ignoring the bitmap.
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.IO;
using System.IO;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace Camera_Test
{
public partial class Program
{
private GT.Timer timer;
void ProgramStarted()
{
serialCameraL2.ImageResolution = SerialCameraL2.Resolution.QQVGA;
this.serialCameraL2.StartStreaming();
this.timer = new GT.Timer(100);
this.timer.Tick += this.timer_Tick;
this.timer.Start();
}
private void timer_Tick(GT.Timer timer)
{
if (this.serialCameraL2.NewImageReady)
{
Bitmap image = this.serialCameraL2.GetImage();
this.displayTE35.SimpleGraphics.DisplayImage(image, 0, 0);
while (!sdCard.IsCardInserted) Thread.Sleep(1000);
if (!sdCard.IsCardMounted) sdCard.Mount();
while (!sdCard.IsCardMounted) System.Threading.Thread.Sleep(50);
byte[] data = image.GetBitmap();
VolumeInfo[] vi2 = VolumeInfo.GetVolumes();
if (vi2[0].IsFormatted)
{
try
{
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
FileStream FileHandle = new FileStream(rootDirectory + @ "\picture.bmp", FileMode.Create);
FileHandle.Write(data, 0, data.Length);
FileHandle.Close();
Debug.Print("Picture stored on sd");
Debug.Print("Finalize volumes");
VolumeInfo[] vi = VolumeInfo.GetVolumes();
for (int i = 0; i < vi.Length; i++)
vi[i].FlushAll();
}
catch (Exception exp)
{
Debug.Print(exp.Message.ToString());
}
}
else
{
Debug.Print("Storage is not formatted. " + "Format on PC with FAT32/FAT16 first!");
}
serialCameraL2.StopStreaming();
}
}
}
}