.NET Gadgeteer Camera,Touch Screen, and Storage

This device is implemented using the modules and mainboard that ship with the GHI Electronics Spider Kit for Micorosoft .NET Gadgeteer.  It uses the GHI Electronics .NET Gadgeteer Display T35 Module touch screen to activate the camera and to display bitmaps captured by the camera.  The device is powered by the USB Client DP Module (UsbClientDP) connected to the USB port of the development computer.  The DP Module also provides a conduit to load assemblies to the mainboard.

After the device boots, a touch to the display screen activates the camera, which starts streaming bitmaps.  The display module shows each frame as it is captured.  A second touch to the screen stops the camera and provides the option to save the last frame to storage on an SD card Module for .NET Gadgeteer socket type F.

A LED module turns red when the camera is streaming bitmaps and green when streaming stops.  After several bitmaps have been captured and saved to the SD Card storage, pushing the button module starts display of all the bitmaps that have been stored on the SD card.

The following illustration shows the device in the Microsoft Visual Studio .NET Gadgeteer Designer.

Touch Screen Camera SDCard in .NET Gadgeteer Designer

Touch Screen Camera SDCard in .NET Gadgeteer Designer

The following code runs the Camera, Touch Screen, SD Card example.  Saving the image to storage depends on a utility function that is exclusive to the GHI Spider Kit for .NET Gadgeteer.  (See the comments for more information on the util library that contains this function.)

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using System.Collections;
using System.IO;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.System;

namespace SDCardCameraTouchScreen
{
    public partial class Program
    {
        Window mainWindow;
        StackPanel stackPanel;
        Bitmap currentBitmapData;

        Image saveImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SaveImg));
        Image skipImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SkipImg));
        ArrayList buttons = new ArrayList();

        uint imageNumber = 0;

        void ProgramStarted()
        {
            // Do one-time tasks here
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            camera.BitmapStreamed += new Camera.BitmapStreamedEventHandler(camera_BitmapStreamed);
            SetupDisplay();
            led.TurnGreen();

            Debug.Print("Program Started");

            display.SimpleGraphics.DisplayTextInRectangle(
                "Touch screen to start streaming bitmaps. Touch again to stop and save picture.",
                50, 50, 250, 200, GT.Color.Green, Resources.GetFont(Resources.FontResources.NinaB),
                GTM.Module.DisplayModule.SimpleGraphicsInterface.TextAlign.Left,
                GTM.Module.DisplayModule.SimpleGraphicsInterface.WordWrap.Wrap,
                GTM.Module.DisplayModule.SimpleGraphicsInterface.Trimming.WordEllipsis,
                GTM.Module.DisplayModule.SimpleGraphicsInterface.ScaleText.ScaleToFit);

            System.Threading.Thread.Sleep(4000);
        }

        void SetupDisplay()
        {
            mainWindow = display.WPFWindow;
            stackPanel = new StackPanel(Orientation.Horizontal);
            stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
            stackPanel.SetMargin(4);
            stackPanel.Children.Add(saveImage);
            stackPanel.Children.Add(skipImage);

            buttons.Add(saveImage);
            buttons.Add(skipImage);
            foreach (Image button in buttons)
                button.Visibility = Visibility.Hidden;

            mainWindow.Child = stackPanel;

            mainWindow.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(mainWindow_TouchDown);

        }

        void ShowButtons()
        {
             foreach (Image button in buttons)
                button.Visibility = Visibility.Visible;

            saveImage.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(saveImage_TouchDown);
            skipImage.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(skipImage_TouchDown);

            mainWindow.Invalidate();
        }

        void HideButtons()
        {
            foreach (Image button in buttons)
            {
                button.Visibility = Visibility.Hidden;
            }

            skipImage.TouchDown -= new Microsoft.SPOT.Input.TouchEventHandler(skipImage_TouchDown);
            saveImage.TouchDown -= new Microsoft.SPOT.Input.TouchEventHandler(saveImage_TouchDown);

            mainWindow.Invalidate();
        }

        void skipImage_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            HideButtons();
        }

        void saveImage_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            if (VerifySDCard())
            {
                GT.StorageDevice storage = sdCard.GetStorageDevice();
                imageNumber = (uint)storage.ListFiles("\\SD\\").Length;

                byte[] bytes = new byte[currentBitmapData.Width *
                                                    currentBitmapData.Height * 3 + 54];
                Util.BitmapToBMPFile(currentBitmapData.GetBitmap(), currentBitmapData.Width,
                                                                  currentBitmapData.Height, bytes);
                GT.Picture picture = new GT.Picture(bytes, GT.Picture.PictureEncoding.BMP);

                string pathFileName = "\\SD\\Image-" + (imageNumber++).ToString() + ".bmp";

                try
                {
                    storage.WriteFile(pathFileName, picture.PictureData);
                }
                catch (Exception ex)
                {
                    Debug.Print("Message: " + ex.Message + "  Inner Exception: " + ex.InnerException);
                }
            }

            HideButtons();
        }

        void mainWindow_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Visible)
                return;

            if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Hidden &&
                                                           led.GetCurrentColor() == GT.Color.Red)
            {
                ShowButtons();
                camera.StopStreamingBitmaps();
                led.TurnGreen();
            }
            if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Hidden &&
                                                           led.GetCurrentColor() == GT.Color.Green)
            {
                HideButtons();
                camera.StartStreamingBitmaps(new Bitmap(camera.CurrentPictureResolution.Width,
                                                          camera.CurrentPictureResolution.Height));
                led.TurnRed();
            }
        }

        void camera_BitmapStreamed(Camera sender, Bitmap bitmap)
        {
            display.SimpleGraphics.DisplayImage(bitmap, 0, 0);
            currentBitmapData = bitmap;
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            button.TurnLEDOn();

            if (VerifySDCard())
            {
                GT.StorageDevice storage = sdCard.GetStorageDevice();

                foreach (string s in storage.ListRootDirectorySubdirectories())
                {
                    Debug.Print(s);
                    if (s == "SD")
                    {
                    foreach (string f in storage.ListFiles("\\SD\\"))
                        {
                            Bitmap bitmap = storage.LoadBitmap(f, Bitmap.BitmapImageType.Bmp);
                            display.SimpleGraphics.DisplayImage(bitmap, 0, 0);
                            System.Threading.Thread.Sleep(2000);
                        }
                    }
                }
            }

            button.TurnLEDOff();
        }

        bool VerifySDCard()
        {
            if (!sdCard.IsCardInserted || !sdCard.IsCardMounted)
            {
                display.SimpleGraphics.DisplayText("Insert SD card!",
                        Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Cyan, 20, 50);

                System.Threading.Thread.Sleep(2000);
                display.SimpleGraphics.ClearNoRedraw();

                led.BlinkRepeatedly(GT.Color.Orange);
                return false;
            }

            return true;
        }
    }
}

  1. #1 by Marco Minerva on November 12, 2011 - 9:29 AM

    Hi!

    In the saveImage_TouchDown event, you use the Util.BitmapToBMPFile method, but where is this method defined? Do I need to add a reference to the project?

  2. #2 by Michael Dodaro on November 12, 2011 - 11:14 AM

    Good question, Marco! You caught this obscure reference. It is, in fact, a specific GHI Electronics library. It is included in this project by the directive: using GHIElectronics.NETMF.System.
    On my system the dll is here:
    C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.1 SDK\Assemblies\be
    If it was not installed with the GHI Electronics Spider Kit, I think it is available from the manufacturer. If you can’t find it, let me know. I think I can get it to you.

  3. #5 by Marco Minerva on November 12, 2011 - 11:20 AM

    Thank you very much, this library ships with GHI Electronics Spider Kit, so no problem adding it to the project!

  4. #6 by Franz on December 31, 2011 - 6:14 AM

    Sorry, but I am new to C# how to add this dll
    I get ” no definition for “GetBitmap” and “BitmapResources”.
    Please help.

    • #7 by Michael Dodaro on December 31, 2011 - 9:44 AM

      In this case I don’t think you need another reference. The objects you’re looking for are C# resources. Here is a link to an MSDN topic that describes how to use resources in C# projects: http://msdn.microsoft.com/en-us/library/7k989cfy(VS.80).aspx

      To add a reference to a C# project, right click on references in the Solution explorer. Next, click the .NET tab and scroll down to the library you need.

      • #8 by workhard10 on January 24, 2012 - 6:43 AM

        Excuse me, I have the same problem, where can I find the “Resources.GetBitmap” or “Resources.BitmapResources.”?

        I am confused about it. I need some Help.

  5. #9 by Michael Dodaro on January 24, 2012 - 7:56 AM

    To use this code:
    Image saveImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SaveImg));
    Image skipImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SkipImg));

    You have to create the bitmaps in Paint or some similar program and add them to your project. Right click the resources folder in Visual Studio Solution Explorer. Add the existing .bmp files that you created in Paint. Then Resources,BitmapResources will include the files in the Intellisense display when you type the period after BitmapResources.

    • #10 by workhard10 on January 24, 2012 - 7:57 AM

      I got it!! thank you very much sir!!

  6. #11 by Bert on February 4, 2012 - 2:05 PM

    I added the two bitmaps, even by using the ADD function , rightclicking Resource Folder,
    but i still get the message that thereferenc to Bitmapresources….

    “Error 2 ‘SDCardCameraTouchScreen.Resources’ does not contain a definition for ‘BitmapResources’ C:\Users\BertO\AppData\Local\Temporary Projects\SDCardCameraTouchScreen\Program.cs 23 67 SDCardCameraTouchScreen

    How do i FInd the reference. I have your CODE copied 1:1 and no errors on unreferenced libraries.

    thenks
    Bert

    • #12 by wintonlin on February 16, 2012 - 6:57 PM

      Hi Bert. I get the same error like you.
      I read your post, but still not solve it.
      What bitmaps should I add in the Resource Folder?
      I am confused.
      Could I use the Paint to create two bitmap files?
      What are the names for the bitmap files?
      I add two bitmaps, but the error still occurred.
      Thanks.

      • #13 by wintonlin on February 16, 2012 - 7:31 PM

        I solve it, after I debugs once, its works.

  7. #14 by Bert on February 4, 2012 - 2:38 PM

    OK i found the resources problem (well the solution actually). You have to add the images directly in the existing recource file. Open the Resource.resx file, choose ADD…Image and then add it there. Adding existing pictures directly to the folder will not work.

    Bert

    • #15 by Michael Dodaro on February 4, 2012 - 2:45 PM

      Great! I just sat down to look at this, but you’re way ahead of me. The sun is shining here today and it’s Saturday, so I’m a little slow.

    • #16 by oakninja@gmail.com on February 20, 2012 - 3:24 PM

      Merci! 🙂

      Now i got it!

      • #17 by alphaoflifeblog on May 19, 2016 - 11:46 PM

        what names have to given to pictures that u have added

    • #18 by alphaoflifeblog on May 19, 2016 - 11:52 PM

      i added the pictures in resources.resx,but still getting error

  8. #19 by Franz on February 7, 2012 - 1:50 AM

    Hi !
    I finally succeeded to run your code. Thank you.
    What surprises me, is that the screen commands to make the buttons visible or to bring up the camera stream to the screen are not working all the time (in whatever mode, debug or release). In addition storing the picture takes more than 20 seconds. All other reactions like touching the screen and pressing the button are really slow as well.
    I wonder if my hardware is ok.

    Franz

    • #20 by Michael Dodaro on February 7, 2012 - 7:54 AM

      That is unexpected behavior in regard to my experience with this scenario. Have you upgraded to latest SDK builds at GHI and reflashed your mainboard? You might also inquire on the .NET Gadgeteer forum: http://www.netmf.com/gadgeteer/forum/ .

  9. #21 by Franz on February 7, 2012 - 11:27 AM

    Thank you for your tip. I did upgrade and flash the mainboard. Now the board is behaving like it should.
    Franz

  10. #23 by wintonlin on February 16, 2012 - 7:43 PM

    Dear Michael :

    I test your code. buy why the saveImage and skipImage button don’t show on the display?

    Thanks

    • #24 by Mike Dodaro on February 16, 2012 - 8:15 PM

      You have to touch the display to show the images. See the video.

      • #25 by wintonlin on February 16, 2012 - 9:12 PM

        I touch it. But only shows white screen. Very strange. The StreamingBitmaps works fine.

  11. #26 by Michael Dodaro on February 17, 2012 - 9:46 AM

    When I have seen the white screen, there has been some electrical glitch that makes the mainboard reboot. Check all your connections. Another user had to reflash his mainboard. Has you mainboard been reflashed with latest upgrade? Check for upgrade: http://www.tinyclr.com/support/

    • #27 by wintonlin on February 19, 2012 - 7:18 PM

      Dear Michael: My mainboard has latest upgrade. And for the white screen, after I touch again ,the StreamingBitmaps start again.
      For the SD card, how much time does the SD card to store a picture?
      I take the SD card storage code from your project to store picture.
      The code can work, but I don’t know is it a efficient code?
      Sometimes the storage is not finished when the timer is too short.
      void OnPictureCaptured(Camera sender, GT.Picture picture)
      {

      if (VerifySDCard())
      {

      GT.StorageDevice storage = sdCard.GetStorageDevice();
      imageNumber = (uint)storage.ListFiles(“\\SD\\”).Length;
      Bitmap bitmap = picture.MakeBitmap();
      currentBitmapData = bitmap;
      byte[] bytes = new byte[currentBitmapData.Width *
      currentBitmapData.Height * 3 + 54];
      Util.BitmapToBMPFile(currentBitmapData.GetBitmap(), currentBitmapData.Width,
      currentBitmapData.Height, bytes);
      string pathFileName = “\\SD\\Image-” + (imageNumber++).ToString() + “.bmp”;

      try
      {
      storage.WriteFile(pathFileName, picture.PictureData);

      }
      catch (Exception ex)
      {
      Debug.Print(“Message: ” + ex.Message + ” Inner Exception: ” + ex.InnerException);
      }
      }

      timer.Restart();
      }

      Anyway, your blog is very very useful for me to learn many. Thank you very much.

      • #28 by Michael Dodaro on February 19, 2012 - 10:51 PM

        If you want to zip up your project and send it to me or put it on a sky drive someplace, I’ll take a look, and possibly run it on my system to see what happens. If it runs on my system, it must be a hardware problem in your case.

  12. #29 by Michael Dodaro on February 20, 2012 - 8:01 AM

    I heard this morning that there is a problem with the SD card on the January 6 version of the SDK from GHI Electronics. Wintonlin, this might be the problem with your app.

  13. #30 by Richard on February 27, 2012 - 2:58 PM

    Hi Michael
    I just wanted to let you know how much I appreciate the SDcardcamera example. I have typed it out and learnt an enormous amount in just two days of debugging. Many thanks. It has made the C# book I read (by John Allwork) much more intelligible.

    Now I am hoping to find an example that will help me use SPI to upload 16bit LF (<500Hz) audio on two channels…

    Richard

  14. #32 by Michael Girard on April 24, 2012 - 8:39 PM

    Hi Michael,

    I’m very dusty on my C. I haven’t programmed in it since the early 90s. I was trying you project to get myself familiar with it again but have got an issue. Like a previous commenter I am having a problem with “Resources.GetBitmap” or “Resources.BitmapResources.” I get an error saying “Error 1 ‘SDCardCameraTouchScreen.Resources’ does not contain a definition for ‘GetBitmap'” and ‘SDCardCameraTouchScreen.Resources’ does not contain a definition for ‘BitmapResources'”

    I have added the SaveImg.bmp and SkipImg.bmp but still get the error. What am I doing wrong?

    ~Michael

    • #33 by Michael Dodaro on April 24, 2012 - 9:39 PM

      In order to get those bitmaps to show in Resources, you have to double click Resources.resx in the Solution Explorer and then add them from the Add Resource/New Image drop down list.

  15. #34 by Michael Girard on April 25, 2012 - 10:45 AM

    I see thats what already you said above and assumed it was what I already had done. I’m a little slow sometime. I did as you mentioned and its all set.

    Thanks Michael,

  16. #35 by Nick Graziadio on May 22, 2012 - 9:21 AM

    I got this error; Field ‘SDCardCameraTouchScreen.Program.currentBitmapData’ is never assigned to, and will always have its default value null. Where in the code does the currentBitmapData = “//insert value here”???

    • #36 by Michael Dodaro on May 22, 2012 - 9:34 AM

      The assignment is made when the camera streams a bitmap, in this event handler:
      void camera_BitmapStreamed(Camera sender, Bitmap bitmap)
      {
      display.SimpleGraphics.DisplayImage(bitmap, 0, 0);
      currentBitmapData = bitmap;
      }
      You can ignore that warning and run the program.

  17. #37 by Giacomo on January 30, 2013 - 9:24 AM

    Hi mike,

    I have a problem:

    When you use GetBitmap and BitmapResource, on my system an error is reported which says:

    ‘SDCardCameraTouchScreen.Resources’ does not contain a definition for ‘BitmapResources’

    C:\Users\giacomo\Desktop\Storage\Program.cs 25 67 SDCardCameraTouchScreen

    Do you know what could this be?

  18. #38 by Michael Dodaro on January 30, 2013 - 9:33 AM

    I think comment #12 above may help solve this problem.

    • #39 by Michael Dodaro on January 30, 2013 - 9:38 AM

      Sorry, wrong thread. Start at the beginning of the comments with Marco’s question and follow that discussion. I think you’ll get the idea.

  19. #40 by David on September 9, 2013 - 12:47 PM

    Dear Mike,
    Writing in VB and having problems saving a succesfully captured image to SD. Can you point me in the right direction? :

    serCam.StartStreaming()
    Do Until serCam.isNewImageReady
    Loop
    display_T35.SimpleGraphics.Clear()
    serCam.DrawImage(LCD, 0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight)
    display_T35.SimpleGraphics.DisplayImage(LCD, 0, 0)
    serCam.StopStreaming()
    ‘Now write to SD card
    Mainboard.SetDebugLED(True)
    If sdCard.IsCardInserted Then
    sdCard.MountSDCard()
    Do Until sdCard.IsCardMounted
    Loop
    ‘Save image
    rootDirectory = sdCard.GetStorageDevice().RootDirectory
    Debug.Print(rootDirectory & “\\img” & imgNo.ToString & “.bmp”)
    sdCard.GetStorageDevice().WriteFile(rootDirectory & “\\img” & imgNo.ToString & “.bmp”, LCD.GetBitmap())
    sdCard.UnmountSDC

    • #41 by Michael Dodaro on September 9, 2013 - 12:54 PM

      I suspect the problem is the utility library as discussed in earlier comments.

  20. #42 by Shak Kwok on November 4, 2014 - 5:21 PM

    This is a great sample if I can make it work. But I am new to C# and gadgeteer.
    So please be patient with my dumb question.
    When I add “using GHIElectronics.NETMF.System:, it complains “are you missing
    an assembly reference?”.
    Based on the comments here, I click view, then solution explorer, then right click
    add reference. The .NET tab comes. Now the question is which one shall I add ?
    I tried several ones as “trial-and-error” with no luck.
    Any help is appreciated.
    SK

    • #43 by Michael Dodaro on November 5, 2014 - 9:25 AM

      Can’t be sure anymore, but it’s likely GHIElectronics.NETMF that contains the System lib you need.

      • #44 by Shak Kwok on November 5, 2014 - 1:31 PM

        Hi Mike,
        Thanks for your reply.
        The problem is I have error when adding
        using GHIElectronics.NETMF.System;

        using GHIElectronics.xxx only allows
        xxx to be Gadgeteer. Anything else(such as NETMF) has error.
        The .NET pops with all the references 4.3.1. Your sample was
        written >2 years ago, with 4.1, can this be the cause?
        Also do you have any training class? I will like to bring all the
        modules, go to your class, and have them work in the class.
        Spending some money is fine. I am wasting my time spinning
        my head.

      • #45 by Michael Dodaro on November 5, 2014 - 1:40 PM

        You will have to substitute current editions. I’d suggest the GHI Electronics community for current specs: https://www.ghielectronics.com/technologies/gadgeteer
        Depends where you live whether you can get some personal instruction. I’m a writer not a speaker, but thanks for asking, Shak.

  21. #46 by alphaoflifeblog on May 20, 2016 - 12:16 AM

    hi mike,

    ‘final3.Resources’ does not contain a definition for ‘BitmapResources’

    i added the bitmap images to resources.resx by double click on resources.resx as discussed above.after that i debug many times still i am getting the problem the code is as follows

    using System;
    using Microsoft.SPOT;
    using Microsoft.SPOT.Presentation;
    using Microsoft.SPOT.Presentation.Controls;
    using Microsoft.SPOT.Presentation.Media;
    using System.Collections;
    using System.Threading;
    using Microsoft.SPOT.Presentation.Shapes;
    using Microsoft.SPOT.Touch;
    using System.IO;

    using GT = Gadgeteer;
    using GTM = Gadgeteer.Modules;
    using Gadgeteer.Modules.GHIElectronics;
    using GHIElectronics.NETMF.System;
    using GHI.Premium.IO;
    //using GHI.Utilities;
    //using GHI.IO.Storage;

    namespace final3
    {
    public partial class Program
    {

    Window mainWindow;
    StackPanel stackPanel;
    Bitmap currentBitmapData;
    Bitmap GetBitmap;

    Image saveImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SaveImg),Bitmap.BitmapImageType.Bmp);
    //Image saveImage=new Image(Resources.GetBitmap(Resources.BitmapResources.SaveImg,Bitmap.BitmapImageType.Bmp));

    Image skipImage = new Image(Resources.GetBitmap(Resources.BitmapResources.SkipImg));
    ArrayList buttons = new ArrayList();

    uint imageNumber = 0;

    void ProgramStarted()
    {
    // Do one-time tasks here
    button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
    camera.BitmapStreamed += new Camera.BitmapStreamedEventHandler(camera_BitmapStreamed);
    SetupDisplay();

    Debug.Print(“Program Started”);
    displayTE35.SimpleGraphics.DisplayTextInRectangle(“Touch screen to start streaming bitmaps. Touch again to stop and save picture.”,
    50, 50, 250, 200, GT.Color.Green, Resources.GetFont(Resources.FontResources.NinaB),
    GTM.Module.DisplayModule.SimpleGraphicsInterface.TextAlign.Left,
    GTM.Module.DisplayModule.SimpleGraphicsInterface.WordWrap.Wrap,
    GTM.Module.DisplayModule.SimpleGraphicsInterface.Trimming.WordEllipsis,
    GTM.Module.DisplayModule.SimpleGraphicsInterface.ScaleText.ScaleToFit);

    System.Threading.Thread.Sleep(4000);
    }

    void SetupDisplay()
    {
    mainWindow = displayTE35.WPFWindow;
    stackPanel = new StackPanel(Orientation.Horizontal);
    stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
    stackPanel.SetMargin(4);
    stackPanel.Children.Add(saveImage);
    stackPanel.Children.Add(skipImage);

    buttons.Add(saveImage);
    buttons.Add(skipImage);
    foreach (Image button in buttons)
    button.Visibility = Visibility.Hidden;

    mainWindow.Child = stackPanel;

    mainWindow.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(mainWindow_TouchDown);

    }

    void ShowButtons()
    {
    foreach (Image button in buttons)
    button.Visibility = Visibility.Visible;

    saveImage.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(saveImage_TouchDown);
    skipImage.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(skipImage_TouchDown);

    mainWindow.Invalidate();
    }

    void HideButtons()
    {
    foreach (Image button in buttons)
    {
    button.Visibility = Visibility.Hidden;
    }

    skipImage.TouchDown -= new Microsoft.SPOT.Input.TouchEventHandler(skipImage_TouchDown);
    saveImage.TouchDown -= new Microsoft.SPOT.Input.TouchEventHandler(saveImage_TouchDown);

    mainWindow.Invalidate();
    }

    void skipImage_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
    {
    HideButtons();
    }

    void saveImage_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
    {
    if (VerifySDCard())
    {
    GT.StorageDevice storage = sdCard.GetStorageDevice();
    imageNumber = (uint)storage.ListFiles(“\\SD\\”).Length;

    byte[] bytes = new byte[currentBitmapData.Width *
    currentBitmapData.Height * 3 + 54];
    Util.BitmapToBMPFile(currentBitmapData.GetBitmap(), currentBitmapData.Width,
    currentBitmapData.Height, bytes);
    GT.Picture picture = new GT.Picture(bytes, GT.Picture.PictureEncoding.JPEG);

    string pathFileName = “\\SD\\Image-” + (imageNumber++).ToString() + “.jpg”;

    try
    {
    storage.WriteFile(pathFileName, picture.PictureData);
    }
    catch (Exception ex)
    {
    Debug.Print(“Message: ” + ex.Message + ” Inner Exception: ” + ex.InnerException);
    }
    }

    HideButtons();
    }

    void mainWindow_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
    {
    if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Visible)
    return;

    if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Hidden)
    {
    ShowButtons();
    camera.StopStreamingBitmaps();

    }
    if (saveImage.Visibility == Microsoft.SPOT.Presentation.Visibility.Hidden )
    {
    HideButtons();
    camera.StartStreamingBitmaps(new Bitmap(camera.CurrentPictureResolution.Width,
    camera.CurrentPictureResolution.Height));

    }
    }

    void camera_BitmapStreamed(Camera sender, Bitmap bitmap)
    {
    displayTE35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
    currentBitmapData = bitmap;
    }

    void button_ButtonPressed(Button sender, Button.ButtonState state)
    {

    if (VerifySDCard())
    {
    GT.StorageDevice storage = sdCard.GetStorageDevice();

    foreach (string s in storage.ListRootDirectorySubdirectories())
    {
    Debug.Print(s);
    if (s == “SD”)
    {
    foreach (string f in storage.ListFiles(“\\SD\\”))
    {
    Bitmap bitmap = storage.LoadBitmap(f, Bitmap.BitmapImageType.Bmp);
    displayTE35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
    System.Threading.Thread.Sleep(2000);
    }
    }
    }
    }

    }

    bool VerifySDCard()
    {
    if (!sdCard.IsCardInserted || !sdCard.IsCardMounted)
    {
    displayTE35.SimpleGraphics.DisplayText(“insert sd card! “, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Cyan, 20, 50);

    System.Threading.Thread.Sleep(2000);
    displayTE35.SimpleGraphics.ClearNoRedraw();

    return false;
    }

    return true;
    }
    }
    }

  1. Benjii Me » What is Gadgeteer? – Getting Started

Leave a comment